Database Reference
In-Depth Information
This concept will get further clarified once we start looking at
the following real world examples.
Example
SELECT *
FROM emp
WHERE sal IN (SELECT sal
FROM emp
WHERE deptno = 30);
Based on the technique that we have defined, we will first
imagine the output of the bottom most query. It will give us all
the salary values from department number 30. Now replace this
query with those imagined values.
Even if multiple values appear as a result of bottom query we
can still use them with IN operator. But the following query will
result in an error if the bottom SELECT statement results in
multiple values.
SELECT *
FROM emp
WHERE sal = (SELECT sal
FROM emp
WHERE deptno = 30);
So be careful when you use operators with sub-queries. The
syntax of the function, clause or Operator should justify under all
circumstances then you are allowed to use sub-queries wherever
you like.
Search WWH ::




Custom Search