SQL SELECT DISTINCT syntax and usage tutorial
This chapter explains how to select discrete speech.
Select different declarations in SQL
In a table, some columns may contain duplicate values. This is not a problem, however, sometimes you want to list only different (different) values on the table.
Can be used to return only unique (different) values.
Select different SQL syntax
SELECT DISTINCT column_name(s)FROM table_name
Select different examples
In the "person" table:
P_Id |
LastName |
FirstName |
Address |
City |
1 |
Hansen |
Ola |
Timoteivn 10 |
Sandnes |
2 |
Svendson |
Tove |
Borgvn 23 |
Sandnes |
3 |
Pettersen |
Kari |
Storgt 20 |
Stavanger |
Now, we only want to select different values from the column named "city" from the above table.
We use the following SELECT statement:
SELECT DISTINCT City FROM Persons
The result-set will look like this:
Note: For reprint, please indicate that it is from www.111cn.cn/database/database.html