tags:

views:

2688

answers:

2

Can you get the distinct combination of 2 different fields in a database table? if so, can you provide the SQL example.

+6  A: 

How about simply:

select distinct c1, c2 from t

or

select c1, c2, count(*)
from t
group by c1, c2
Decker
A: 

If you want distinct values from only two fields, plus return other fields with them, then the other fields must have some kind of aggregation on them (sum, min, max, etc.), and the two columns you want distinct must appear in the group by clause. Otherwise, it's just as Decker says.

Jeffrey L Whitledge