SQL tutorial | Interview questions | Oracle
Would you like to react to this message? Create an account in a few clicks or log in to continue.

How To Filter Out Duplications in the Returning Rows?

Go down

How To Filter Out Duplications in the Returning Rows? Empty How To Filter Out Duplications in the Returning Rows?

Post by Micheal Sun Jan 17, 2010 3:04 am

If there are duplications in the returning rows, and you want to remove the duplications, you can
use the keyword DISTINCT or UNIQUE in the SELECT clause. The tutorial exercise below shows
you that DISTINCT works on selected columns only:
SQL> CREATE TABLE fyi_team AS
SELECT first_name, last_name FROM employees
WHERE first_name = 'John';
Table created.
SQL> INSERT INTO fyi_team VALUES ('John', 'Chen');
SQL> INSERT INTO fyi_team VALUES ('James', 'Chen');
SQL> INSERT INTO fyi_team VALUES ('Peter', 'Chen');
SQL> INSERT INTO fyi_team VALUES ('John', 'Chen');
SQL> SELECT * FROM fyi_team;
FIRST_NAME LAST_NAME
-------------------- -------------------------
John Chen
John Russell
John Seo
John Chen
James Chen
Peter Chen
John Chen
SQL> SELECT DISTINCT * FROM fyi_team;
FIRST_NAME LAST_NAME
-------------------- -------------------------
Peter Chen
John Chen
James Chen
John Seo
John Russell
SQL> SELECT DISTINCT last_name FROM fyi_team;
LAST_NAME
-------------------------
Chen
Russell
Seo

Micheal
Admin

Posts : 243
Join date : 2010-01-10

http://sql-tutorial.co.cc

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum