tags:

views:

45

answers:

1
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  -?-

I want distinct values on the basis of only "handel column" and "Title column". For example, Handel: 902D8 and Title: -?- should only appear once

The result of query on above data should be

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

Many Thanks.

+1  A: 
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)
Salil
A more efficent solution can be obtained with OLAP functions (also known as analytic functions) if the environment support them (DB2 and Oracle does), but judging from the tags we are talking about ms-access so your answer is the best possible I think.
Andrea Polci
@ Salil - I added the primary key and it worked with that, though very slow in execution but worked for me. Thanks alot.
HTMZ
@Andrea Polci: the MS-ACCESS tag can mean that the front end is Access and the back end datastore is just about any database engine in existence, so your mention of the OLAP functions is potentially helpful, if not to this particular questioner, possibly to someone coming on the question later.
David-W-Fenton