SELECT DISTINCT.. FROM:
SELECT DISTINCT..FROM is used to eliminate duplicate values in the table. The syntax is:
SELECT DISTINCT ColumnName, ColumnName, ...
FROM TableName;
Lets us look at the following table (tbl_employee) including five fields:
Social_Security , Last_Name, First_Name, Address and Zip_Code:
Social_Security | Last_ Name | First_Name | Address | Zip_Code |
476-02-3475 | Mitchel | John | 1223 West Palm Beach Rd | 85023 |
376-76-9083 | Spencer | Teri | 2349 S. 76th Street #102 | 53219 |
733-05-3598 | James | Taylor | 23 N. Atlantic Blvd | 76215 |
387-41-1189 | Pewinsky | Lewis | 675 E Indian School Rd | 85023 |
498-32-9089 | James | Sue | 3567 E Tatum Blvd | 85032 |
If you want to retrive distinct employee names, use the following statement:
SELECT DISTINCT Last_Name, First_Name FROM tbl_employee
The result from the command is:
Last_Name | First_Name | Zip_Code |
Mitchel | John | 85023 |
Spencer | Teri | 53219 |
James | Taylor | 76215 |
Pewinsky | Lewis | 85023 |
Notice how in the result set, only the first employee with the last name "James " is included. This command is useful if you are looking at duplicate information and trying to limit the final result