0

Why we need to add all ORDER BY column names in SELECT clause when we are using DISTINCT in SELECT?

Example : Following first query execute but second prompt error. 1] SELECT DISTINCT EId, Email, FirstName, LastName FROM Employee WHERE FirstName ='Yash' ORDER BY FirstName, LastName 2] SELECT DISTINCT EId, Email, FirstName FROM Employee WHERE FirstName ='Yash' ORDER BY FirstName, LastName

14th Jun 2017, 5:19 AM
Gladiator
Gladiator - avatar
1 Antwort
+ 7
because you don't select Last Name but you try to order by it in the second. order by works on the "extracted" data, not on the original table (database), so if you did not include it in the Select it just does not exist for it.
14th Jun 2017, 5:44 AM
Nikolay Nachev
Nikolay Nachev - avatar