The SELECT command allows us to read all the data from one or more fields in a table. This will take all the data out, regardless of whether the data values are duplicated or not. In data processing, we often encounter situations where we need to find out the different data values in the table. In other words, we need to know what the different values are in this table/field, and the number of times each value appears is not important. How is this going to be achieved? In SQL, this is easy to do. We just need to add a DISTINCT to the SELECT . The syntax for DISTINCT is as follows: Select DISTINCT "Field name" From "table name";For example, to find out all the different store names in the following table,store_information, store_information Form
Store_name |
Sales |
Txn_date |
Los Angeles |
1500 |
05-jan-1999 |
San Diego |
250 |
07-jan-1999 |
Los Angeles |
300 |
08-jan-1999 |
Boston |
700 |
08-jan-1999 |
We'll break in,
SELECT DISTINCT store_name from Store_information;Results:
Store_name |
Los Angeles |
San Diego |
Boston
|
|
Test results under Linux:
Reprint please specify: Xiao Liu
A concise tutorial of SQL statements for Linux---DISTINCT