Postgres Query for Distinct Column Values
Q: Write a Postgres query to retrieve distinct values from a specific column in a table using the DISTINCT keyword.
- Postgres
- Senior level question
Explore all the latest Postgres interview questions and answers
ExploreMost Recent & up-to date
100% Actual interview focused
Create Postgres interview for FREE!
To retrieve distinct values from a specific column in a table in Postgres, you can use the SELECT statement with the DISTINCT keyword. Here's an example query:
SELECT DISTINCT column_name
FROM table_name;
Replace "column_name" with the name of the column from which you want to retrieve distinct values, and "table_name" with the actual name of the table.
For example, if you have a table named "Products" and you want to retrieve distinct values from the "category" column, the query would be:
SELECT DISTINCT category
FROM Products;
Executing this query will retrieve all unique values from the "category" column in the "Products" table.
Remember to adjust the column name and table name based on your specific database schema and requirements. The DISTINCT keyword ensures that only distinct values are returned, eliminating duplicates from the result set.


