SQL distinct for 2 fields in a database

leora picture leora · Oct 10, 2008 · Viewed 160.3k times · Source

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

Answer

Howard Pinsley picture Howard Pinsley · Oct 10, 2008

How about simply:

select distinct c1, c2 from t

or

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