SQL > SQL Commands > Select Unique

The SELECT UNIQUE term is an Oracle-only SQL statement. It is equivalent to SELECT DISTINCT. The syntax for SELECT UNIQUE is as follows:

SELECT UNIQUE "column_name"
FROM "table_name";

For example, to select all distinct stores in Table Store_Information,

Table Store_Information

Store_NameSalesTxn_Date
Los Angeles1500Jan-05-1999
San Diego250Jan-07-1999
Los Angeles300Jan-08-1999
Boston700Jan-08-1999

we key in,

SELECT UNIQUE Sales FROM Store_Information;

Result:

Sales
1500
250
300
700

Exercises

For these exercises, assume we have a table called Region_Sales with the following data:

Table Region_Sales

RegionYearOrdersTotal_Sales
West20131560325000
West20141820380000
North2013790148000
North2014995185000
East20131760375000
East20142220450000
South20131790388000
South20141695360000

1. (True or False) The following two statements are equivalent in MySQL:
SELECT UNIQUE Region FROM Region_Sales;
SELECT DISTINCT Region FROM Region_Sales;

2. Which of the following statements are valid in Oracle?
a) SELECT DISTINCT Year FROM Region_Sales;
b) SELECT UNIQUE * FROM Region_Sales;
c) SELECT * FROM Region_Sales;
d) SELECT UNIQUE Year FROM Region_Sales;

3. What is the output for the following statement?
SELECT UNIQUE Region FROM Region_Sales WHERE Orders < 1000;

Next: SQL INSERT INTO




Copyright © 2015   1keydata.com   All Rights Reserved.     Privacy Policy     About   Contact