How To Filter Out Duplications in the Returning Rows?
Page 1 of 1
How To Filter Out Duplications in the Returning Rows?
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
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
Similar topics
» How To Return Top 5 Rows?
» How To Select Some Rows from a Table?
» How To Select All Columns of All Rows from a Table?
» How To Use SELECT Statement to Count the Number of Rows?
» What Privilege Is Needed for a User to Delete Rows from Tables in Another Schema?
» How To Select Some Rows from a Table?
» How To Select All Columns of All Rows from a Table?
» How To Use SELECT Statement to Count the Number of Rows?
» What Privilege Is Needed for a User to Delete Rows from Tables in Another Schema?
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Sun Jan 31, 2010 12:35 am by Micheal
» Accessing tables of other users in SQL
Sun Jan 31, 2010 12:34 am by Micheal
» Grouping commands in SQL
Sun Jan 31, 2010 12:32 am by Micheal
» Operations on Result Sets in SQL
Sun Jan 31, 2010 12:31 am by Micheal
» Subqueries in SQL
Sun Jan 31, 2010 12:30 am by Micheal
» Joining Relations in SQL
Sun Jan 31, 2010 12:28 am by Micheal
» Delete comand in SQL
Sun Jan 31, 2010 12:27 am by Micheal
» Update command in SQL
Sun Jan 31, 2010 12:26 am by Micheal
» Insert command in SQL
Sun Jan 31, 2010 12:23 am by Micheal