How To Filter Out Duplications in the Returning Rows using Oracle?

Submitted by: Administrator
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 ggl_team AS
SELECT first_name, last_name FROM employees
WHERE first_name = 'John';
Table created.
SQL> INSERT INTO ggl_team VALUES ('John', 'Chen');
SQL> INSERT INTO ggl_team VALUES ('James', 'Chen');
SQL> INSERT INTO ggl_team VALUES ('Peter', 'Chen');
SQL> INSERT INTO ggl_team VALUES ('John', 'Chen');
SQL> SELECT * FROM ggl_team;
<pre>FIRST_NAME LAST_NAME
-------------------- -------------------------
John Chen
John Russell
John Seo
John Chen
James Chen
Peter Chen
John Chen</pre>
SQL> SELECT DISTINCT * FROM ggl_team;
<pre>FIRST_NAME LAST_NAME
-------------------- -------------------------
Peter Chen
John Chen
James Chen
John Seo
John Russell</pre>
Submitted by: Administrator

SQL> SELECT DISTINCT last_name FROM ggl_team;
LAST_NAME
-------------------------
Chen
Russell
Seo

Submitted by: Administrator

Read Online Oracle Database Job Interview Questions And Answers