Avoid duplication of values in a SELECT query in PostgreSQL
- by Shyam Solanki
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?