AdBlock Detected!
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.
SQL DISTINCT |
SQL > SQL Commands >
Distinct
In SQL, the DISTINCT keyword is used in the SELECT statement to retrieve unique values from a database table. Any value that has a duplicate will only show up once. SyntaxSELECT DISTINCT "column_name"
FROM "table_name"; "table_name" is the name of the table where data is stored, and "column_name" is the name of the column containing the data to be retrieved. ExamplesThe examples will use the following table: Table Store_Information
Example 1: Use DISTINCT on one columnTo select all distinct stores in Table Store_Information, we key in, SELECT DISTINCT Store_Name FROM Store_Information;
Result:
Example 2: Use DISTINCT on multiple columnsWe can apply DISTINCT to multiple columns. If we want to get a list showing all unique combinations of stores and transaction dates, we would type in the following, SELECT DISTINCT Store_Name, Txn_Date FROM Store_Information;
Result:
ExercisesFor these exercises, assume we have a table called Users with the following data: Table Users
1. Which of the following SQL statement is valid?
2. What's the result of the following query?
3. What's the result of the following query?
|
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.