postgresqlHow do I use the PostgreSQL DISTINCT keyword?
The PostgreSQL DISTINCT keyword is used to select only distinct (unique) values from a column. It eliminates duplicate values from the result set of a query.
For example, if we have a table of users with the following data:
| ID | Name |
|---|---|
| 1 | John |
| 2 | John |
| 3 | Mary |
We can use the DISTINCT keyword to select only the unique values from the Name column:
SELECT DISTINCT Name FROM users;
This would return the following output:
John
Mary
The parts of the statement are:
SELECT: The start of the statement, which indicates that we are selecting data from a table.DISTINCT: This keyword is used to select only unique values from the specified column.Name: The name of the column that we are selecting from.FROM: This keyword indicates the table that we are selecting from.users: The name of the table that we are selecting from.
For more information, see the PostgreSQL documentation.
More of Postgresql
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How do I use PostgreSQL's XMIN and XMAX features?
- How can I monitor PostgreSQL performance using Zabbix?
- How can I integrate PostgreSQL with Yii2?
- How can I use PostgreSQL with YAML?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How do I use PostgreSQL UNION to combine the results of two queries?
- How do I decide whether to use PostgreSQL VARCHAR or TEXT data types?
- How do I use PostgreSQL with Qt?
- How can I retrieve data from PostgreSQL for yesterday's date?
See more codes...