PL/SQL Exists

The EXISTS operator is used to correlate rows from an SELECT statement with the other one being an subquery.

Course table

COURSE_IDNAMEDESCRIPTIONDURATIONPRICE
1SQL 1SQL course for beginners1 week10
2SQL 2SQL course for advanced2 week50
3HTML5Learn HTML 51 week10
4PHPPHP course4 week75
5CSSLearn CSS2 week20

Orders table

ORDER_IDCOURSE_IDSTUDENT_IDORDER_DATE
11607-AUG-2014 10:11:03
25723-SEP-2014 12:31:41
34529-AUG-2014 09:55:54
215601-DEC-2014 16:32:36
321417-DEC-2014 17:22:27

Exists example

 
SELECT * 
FROM course c 
WHERE EXISTS (select * from orders o where o.course_id=c.course_id);

Output

COURSE_IDNAMEDESCRIPTIONDURATIONPRICE
1SQL 1SQL course for beginners1 week10
5CSSLearn CSS2 week20
4PHPPHP course4 week75

Not Exists example

 
SELECT * 
FROM course c 
WHERE NOT EXISTS (select * from orders o where o.course_id=c.course_id);

Output

COURSE_IDNAMEDESCRIPTIONDURATIONPRICE
34529-AUG-2014 09:55:54
25723-SEP-2014 12:31:41