SQL - SELECT DISTINCT statement
SELECT statement is used to select the records from the table. You can specify the wild card (*) to display all the fields or you can specify the column names. What if you want to get the distinct or unique collection of one column? This is the time you have to use SELECT DISTINCT
SELECT DISTINCT LastName FROM Students
The above query will return the following records:
LastName |
---|
Alex |
Sharma |
Kumar |
Kandasamy |
Note that there are two persons with the last name "Kumar".
The select * query will return the following records:
No |
FirstName |
LastName |
Age |
City |
---|---|---|---|---|
1 |
David |
Alex |
19 |
San Francisco |
2 |
Ravi |
Sharma |
18 |
San Jose |
3 |
Surya |
Kumar |
17 |
Milpitas |
4 |
Saravanan |
Kandasamy |
18 |
Cupertino |
5 |
Senthil |
Kumar |
19 |
San Francisco |
|