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 use PostgreSQL and ZFS snapshots together?
- How do I use PostgreSQL aggregate functions?
- How can I set a PostgreSQL interval to zero?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can Zalando use PostgreSQL to improve its software development?
- How do I use PostgreSQL and ZFS together?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How can I use PostgreSQL XML functions to manipulate XML data?
- How can I use PostgreSQL XOR to compare two values?
- How do I export data from PostgreSQL to an XML file?
See more codes...