First page Back Continue Last page Overview Graphics

SQL Sub-Queries

SELECT e.emp_id,fname,lname

FROM (SELECT id,emp_id,fname,lname,start_date

FROM employees

WHERE start_date > "2010-01-01") e

WHERE ABS(e.emp_id) % 2 = 1;

Notes:

Contrived, yes, but something to see the complexity.

Same as:

SELECT e.emp_id,fname,lname

FROM employees

WHERE start_date > "2010-01-01"

AND ABS(e.emp_id) % 2 = 1;

I never see subqueries generated tables used. Possible. But I just

never see them. I type them in sometimes. They are often useful when

just hacking out a query. So wanted to show it. But more often see

LEFT INNER JOIN used instead.