Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
[ NOT ] IN
"(" <basic_expression> ")"
| <expression>
[ NOT ] IN
<subquery> -- single-column result set
Here is an example using IN with a list to show all the employees in the
ASADEMO database with a first name of John, Paul, George, or Ringo:
SELECT emp_id,
emp_fname,
emp_lname
FROM employee
WHERE emp_fname IN ( 'John', 'Paul', 'George', 'Ringo' )
ORDER BY emp_id;
Heres the final result set; three Johns and a Paul but no George or Ringo:
emp_id emp_fname emp_lname
====== ========= =========
318 John Crow
862 John Sheffield
1021 Paul Sterling
1483 John Letiecq
Here is another example using subqueries in two IN predicates to find all the
employees whose first name is the same as someone elses last name, or vice
versa:
SELECT emp_id,
emp_fname,
emp_lname
FROM employee
WHERE emp_fname IN ( SELECT emp_lname
FROM employee )
OR emp_lname IN ( SELECT emp_fname
FROM employee )
ORDER BY emp_id;
The final result set contains two rows, showing that Scott is the only name
that appears as both first and last name in the employee table:
emp_id emp_fname emp_lname
====== ========= =========
501 David Scott
1576 Scott Evans