Click here to Skip to main content
15,885,998 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
SELECT DISTINCT empid FROM empcdetails ORDER BY empdoj

executing the above statement it shows an error as fallows

Error

ORDER BY items must appear in the select list if SELECT DISTINCT is specified


from pradeep
Posted

Yes, ORDER BY clause with DISTINCT keyword needs the column to be specified in the selection list like:

SQL
SELECT DISTINCT empid, empdoj FROM empcdetails ORDER BY empdoj


Thanks
 
Share this answer
 
Comments
Member 9576671 21-Dec-12 1:37am    
thanks ,give an example query
[no name] 21-Dec-12 2:42am    
If this helped you then accept the answer and upgrade it.
Thanks
You can't order by something you did not select, when you use DISTINCT because if there's two empids with different empdoj values, how does it know how to order them ? You need to select empdoj as well ( which means it won't be distinct ) or you need to lose the order by
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900