SELECT
Statement (Cont.)
SELECT DISTINCT
StatementDISTINCT
keyword is used to return only distinct (different) values.
Note that “W3Schools” is listed twice in the result-set if the keyword DISTINCT
is not used.
To select only DIFFERENT
values from the column named Company
we use a SELECT DISTINCT
statement.
SQL> create table Orders ( 2 Company varchar(32), 3 OrderNumber Number(4) ); Table created. SQL> insert into Orders values ('Sega', 3412); 1 row created. SQL> insert into Orders values ('W3Schools', 2312); 1 row created. SQL> insert into Orders values ('Trio', 4678); 1 row created. SQL> insert into Orders values ('W3Schools', 6798); 1 row created. SQL> select Company from Orders; COMPANY -------------------------------- Sega W3Schools Trio W3Schools SQL> select distinct Company from Orders; COMPANY -------------------------------- Sega Trio W3Schools |
Customers
table may be created by the following command:
SQL> create table Customers ( 2 CustomerID varchar(16), 3 CompanyName varchar(32), 4 ContactName varchar(32), 5 Address varchar(64), 6 City varchar(32), 7 PostalCode varchar(16), 8 Country varchar(32) );Note that the
Customers
table is for read only.