Avoid duplication of values in a SELECT query in PostgreSQL

Posted by Shyam Solanki on Stack Overflow See other posts from Stack Overflow or by Shyam Solanki
Published on 2013-10-17T09:14:00Z Indexed on 2014/08/22 16:22 UTC
Read the original article Hit count: 222

Filed under:
|

I have a table named product which contains two columns:

id  name
1   p1
2   p2
3   p1
4   p3
5   p4

I run the following query:

SELECT DISTINCT id, name FROM product;

As a result, PostgreSQL gives me the following output:

id  name
1   p1
2   p2
3   p1
4   p3
5   p4

I want to avoid duplication of values in the name field, so the desired output should look like this:

1   p1
2   p2
4   p3
5   p4

How should I go about achieving this?

© Stack Overflow or respective owner

Related posts about postgresql

Related posts about duplication