ylbtech-SQL-W3School: SQL DISTINCT statement |
1. Back to top |
1、
This chapter explains the SELECT DISTINCT statement.
SQL SELECT DISTINCT statement
In the table, it may contain duplicate values. This is not a problem, but sometimes you may want to just list the different (distinct) values.
DISTINCT keyword is used to return only difference values.
grammar:
SELECT DISTINCT name FROM table column names
Use DISTINCT keyword
If you want to "Company" column, select all the values, we need to use the SELECT statement:
SELECT Company FROM Orders
"Orders"表:
Company | OrderNumber |
---|---|
IBM | 3532 |
W3School | 2356 |
Apple | 4698 |
W3School | 6953 |
result:
Company |
---|
IBM |
W3School |
Apple |
W3School |
Please note, focus on results, W3School was listed twice.
For the Company "column select only difference values only , we need to use the SELECT DISTINCT statement:
SELECT DISTINCT
Company FROM Orders
result:
Company |
---|
IBM |
W3School |
Apple |
Now, in the result set, "W3School" was listed only once.
2、
2. Return to top |
3. Back to top |
4. Top |
5. Top |
1、
2、
6. Back to top |
Author: ylbtech Source: http://ylbtech.cnblogs.com/ This article belongs to the author and blog Park total, welcome to reprint, but without the author's consent declared by this section must be retained, and given the original connection in the apparent position of the article page, otherwise reserves the right to pursue legal responsibilities. |