日期:2014-05-18  浏览次数:20488 次

高人!关于distinct祛除重复和order by的使用
我的sql语句如下:
select distinct detailsId,commodityColor from Details where commodityId='100081' order by commodityColor asc主要是想查出来"commodityColor"并且祛除它的重复项 再按照detailsId排序


问题:
执行结果是把所有的都查出来了,再按照detailsId排序,但是没有达到祛除重复项的效果啊! 有没有人知道怎么办啊??



------解决方案--------------------
order by distinct commodityColor asc 试试
------解决方案--------------------
SQL code
select detailsId = MIN(detailsId),commodityColor --或用max(detailsId)
from Details 
where commodityId='100081'
GROUP BY commodityColor
ORDER BY detailsId

------解决方案--------------------
探讨
SQL code
select detailsId = MIN(detailsId),commodityColor --或用max(detailsId)
from Details
where commodityId='100081'
GROUP BY commodityColor
ORDER BY detailsId

------解决方案--------------------
select detailsId = MIN(detailsId),commodityColor --或用max(detailsId)
from Details
where commodityId='100081'
GROUP BY commodityColor
ORDER BY detailsId