SQL SELECT DISTINCT statement

The SQL SELECT DISTINCT statement
may contain duplicate values ​​in the table. This is not a problem, however, sometimes you may want to just list distinct values.
The keyword DISTINCT is used to return uniquely distinct values.
Syntax:
SELECT DISTINCT column name FROM table name
using DISTINCT keyword
If we want to select all values ​​from "Company" column, we need to use SELECT statement:
SELECT Company FROM Orders
"Orders" Table:
Company    OrderNumber   

IBM             3532   

W3School  2356    

Apple     4698        

W3School 6953      

Results:
Company
IBM
W3School
Apple
W3School
Notice that in the result set, W3School is listed twice.
To select only unique values ​​from the Company" column, we need to use the SELECT DISTINCT statement:
SELECT DISTINCT Company FROM Orders
Result:
Company
IBM
W3School
Apple
Now, in the result set, "W3School" is listed only once.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326566590&siteId=291194637
Recommended