Can you get the distinct combination of 2 different fields in a database table? if so, can you provide the SQL example.
Select with distinct on all columns of the first query. Select with distinct on multiple columns and order by clause. Count() function and select with distinct on multiple columns.
Answer. Yes, the DISTINCT clause can be applied to any valid SELECT query. It is important to note that DISTINCT will filter out all rows that are not unique in terms of all selected columns.
Yes, DISTINCT works on all combinations of column values for all columns in the SELECT clause.
No you can't use that, it will throw an error, but there are other alternatives where you can get your desired results.
How about simply:
select distinct c1, c2 from t
or
select c1, c2, count(*) from t group by c1, c2
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With