DISTINCT
keyword can be used to return only distinct (different) values.
In a table, some of the columns may contain duplicate values.
This is not a problem, however, sometimes you will want to list only the different (distinct) values in a table. |
|
DISTINCT
is not used.
To select only different values from the column named Company, we use a select distinct statement.
CREATE TABLE Orders ( Company VARCHAR(32), OrderNumber NUMBER(4) NOT NULL); Table created. INSERT INTO Orders VALUES ('Sega', 3412); INSERT INTO Orders VALUES ('W3Schools', 2312); INSERT INTO Orders VALUES ('Trio', 4678); INSERT INTO Orders VALUES ('W3Schools', 6798); SELECT Company FROM Orders; COMPANY -------------------------------- Sega W3Schools Trio W3Schools SELECT DISTINCT Company FROM Orders; COMPANY -------------------------------- Sega Trio W3Schools |
For security reasons, the following demonstration may only work in Chrome.
Result:Click “Run SQL” to execute the SQL statement above.
W3Schools has created an SQL database in your browser.
The menu to the right displays the database, and will reflect any changes.
Feel free to experiment with any SQL statement.
You can restore the database at any time.
|
The Database includes:
|
The Database includes:
|