SQL SELECT Statement SELECT UNIQUE
The SQL SELECT Statement SELECT UNIQUE is used to retrieve unique records from a database table. The SELECT UNIQUE statement returns only the distinct values from a column in a table. In this article, we will discuss the syntax, example, output, explanation, use, important points, and summary of the SQL SELECT Statement SELECT UNIQUE.
Syntax
SELECT UNIQUE column_name
FROM table_name;
Example
Suppose we have a table named "customer" with the following data:
customer_id | name | age |
---|---|---|
1 | John | 30 |
2 | Jane | 25 |
3 | Sarah | 35 |
4 | John | 30 |
5 | Jane | 25 |
The SQL SELECT Statement SELECT UNIQUE will return only the distinct values from the name column in the customer table.
SELECT UNIQUE name
FROM customer;
Output
The query will return the following output:
name |
---|
John |
Jane |
Sarah |
Explanation
The SQL SELECT Statement SELECT UNIQUE is used to retrieve only unique records from a column in a table. In the example above, we used the SELECT UNIQUE statement to retrieve only the unique values from the name column in the customer table. The query returned only three distinct values as 'John', 'Jane', and 'Sarah'.
Use
The SQL SELECT Statement SELECT UNIQUE is used when we want to retrieve only the distinct values from a column in a table. It helps to reduce redundancy in data and simplifies the output after selecting data from a table.
Important Points
- The SELECT UNIQUE statement is used to retrieve only unique records from a column in a table.
- The SELECT UNIQUE statement is equivalent to the SELECT DISTINCT statement and is supported by some database management systems such as Oracle and PostgreSQL.
- The SELECT UNIQUE statement can be used with multiple columns in a table to retrieve multiple columns with only unique values.
Summary
The SQL SELECT Statement SELECT UNIQUE retrieves only the distinct values from a column in a table. It helps to reduce redundancy in data and simplifies the output after selecting data from a table. It can be used with multiple columns in a table to retrieve multiple columns with only unique values. The SELECT UNIQUE statement is equivalent to the SELECT DISTINCT statement and is supported by some database management systems such as Oracle and PostgreSQL.