使用两列的组合从表中获取不同的行

时间:2010-04-07 08:13:01

标签: sql ms-access

Status   Time          Handel  Title

---------      ------------     ------       ------------- 
CREATED   2009-10-16 03:37:38+01   902D8   Mozilla Firefox
ACTIVATED 2009-10-16 03:37:38+01  902D8  -?-
ACTIVATED 2009-10-16 03:37:41+01  902D8  -?-
ACTIVATED 2009-10-16 03:37:41+01  E030E  Windows Live Messenger
DESTROYED 2009-10-16 03:37:42+01  E030E  Windows Live Messenger
ACTIVATED 2009-10-16 03:37:42+01  902D8  -?-
DESTROYED 2009-10-16 03:37:53+01  902D8  -?-

我想要仅基于“handel column”和“Title column”的不同值。例如,Handel:902D8和Title: - ? - 应该只出现一次

对上述数据的查询结果应为

Status   Time             Handel  Title
---------    ------------          ------  ------------- 
CREATED   2009-10-16 03:37:38+01   902D8   Mozilla Firefox
ACTIVATED 2009-10-16 03:37:38+01  902D8  -?-
ACTIVATED 2009-10-16 03:37:41+01  E030E  Windows Live Messenger

非常感谢。

1 个答案:

答案 0 :(得分:1)

select * from table where id in (select min(id) from table group by handle, title)   

OR

select * from table where id in (select max(id) from table group by handle, title)