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 Use Subqueries with the EXISTS Operator?

Go down

How To Use Subqueries with the EXISTS Operator? Empty How To Use Subqueries with the EXISTS Operator?

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

A subquery can be used with the EXISTS operator as "EXISTS (subquery)", which returns true if
the subquery returns one or more rows. The following statement is a good example of "EXISTS
(subquery)". It returns rows from employees table that there are rows existing in the departments
table linked to the employees table with location_id = 1700.
SQL> SELECT first_name, last_name FROM employees e
WHERE EXISTS (
SELECT * FROM departments d
WHERE e.department_id = d.department_id AND d.location_id = 1700
);
FIRST_NAME LAST_NAME
-------------------- -------------------------
Steven King
Neena Kochhar
Lex De Haan
Nancy Greenberg
Daniel Faviet
John Chen
Ismael Sciarra

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