Reputation: 3233
I want to return all the rows from a table which are unique. I.e. if a certain field in two rows contain the same name, that name shouldn't be shown.
Upvotes: 0
Views: 151
Reputation: 6748
Since you want only the uniques names (and not an unique row for every names like you could have with DISTINCT
), you have to use a GROUP BY
and a HAVING
(instead of a WHERE
, because your parameter is the result of a function, not a variable) :
SELECT name FROM myTable GROUP BY name HAVING COUNT(name) = 1
Upvotes: 10
Reputation: 1269445
If you want the complete rows, then use row_number()
or distinct on
:
select distinct on (name) t.*
from table t
order by name;
Upvotes: 0