【发布时间】:2011-07-20 11:29:44
【问题描述】:
执行以下语句后:
SELECT Category FROM MonitoringJob ORDER BY CreationDate DESC
我正在从数据库中获取以下值:
test3
test3
bildung
test4
test3
test2
test1
但我希望删除重复项,如下所示:
bildung
test4
test3
test2
test1
我尝试使用 DISTINCT,但它不适用于 ORDER BY 在一个语句中。请帮忙。
重要:
-
我试过了:
SELECT DISTINCT Category FROM MonitoringJob ORDER BY CreationDate DESC它不起作用。
CreationDate 的顺序非常重要。
【问题讨论】:
-
怎么不行?输出错误?
-
如果你使用postgres,显然你可以SELECT DISTINCT ON (value), * FROM table ORDER BY value, and_the_value_you_want_to_order_from DESC
标签: sql sql-order-by distinct