I have a table with multiple columns but I need only 2.
select id, department from tbl
If I want to use distinct
, how do I do that?
This is not working:
select id, distinct department from tbl
Use the following to get distinct rows:
select distinct id, department
from tbl
However, you can't simply get distinct departments if some departments have multiple Id's - you need to figure out which of the multiple Id's you want (max? min? something else?).
SELECT * FROM Table c1
WHERE ID = (SELECT MIN(ID) FROM Table c2
WHERE c1.department = c2.department)
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