如何使用distinct by order by子句 [英] how to use distinct with order by clause
本文介绍了如何使用distinct by order by子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SELECT DISTINCT empid FROM empcdetails ORDER BY empdoj
执行上述声明它显示错误为休闲
错误
如果指定了SELECT DISTINCT,ORDER BY项必须出现在选择列表中
来自pradeep的
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
推荐答案
是的,带有DISTINCT关键字的ORDER BY子句需要在选择列表如:
Yes, ORDER BY clause with DISTINCT keyword needs the column to be specified in the selection list like:
SELECT DISTINCT empid, empdoj FROM empcdetails ORDER BY empdoj
谢谢
Thanks
你不能订购你没有选择的东西,当你使用DISTINCT时,因为如果有两个具有不同empdoj值的empid,它如何知道如何订购它们?您还需要选择empdoj(这意味着它不会是明显的)或者您需要通过
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
这篇关于如何使用distinct by order by子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文