SQL > SQL Commands > Distinct
The SELECT keyword allows us to grab all information from a column (or columns) on a table. This, of course, necessarily means that there will be redundancies. What if we only want to select each DISTINCT element? This is easy to accomplish in SQL. All we need to do is to addDISTINCT after SELECT. The syntax is as follows:
SELECT DISTINCT "column_name"
FROM "table_name";
FROM "table_name";
For example, to select all distinct stores in Table Store_Information,
Table Store_Information
Store_Name | Sales | Txn_Date |
Los Angeles | 1500 | Jan-05-1999 |
San Diego | 250 | Jan-07-1999 |
Los Angeles | 300 | Jan-08-1999 |
Boston | 700 | Jan-08-1999 |
we key in,
SELECT DISTINCT Store_Name FROM Store_Information;
Result:
Store_Name |
Los Angeles |
San Diego |
Boston |
No comments:
Post a Comment