|
|
|
|
|
|
Solution:
We can first find all the male employees: select fname, lname, salary from employee where sex='M' |
Notice that we must use an alias R1 to name the result relation produced by the SELECT command
SELECT .... FROM .... , (SELECT .... ) R1 , (SELECT .... ) R2 , ... WHERE .... ... |
Not allowed: SELECT .... FROM .... , (SELECT .... ) R1 , (SELECT .... FROM R1 ... ) R2 , ... WHERE .... ... |
You cannot use R1 to create R2 !!!
WITH ALIAS as ( SELECT query ) [, ALIAS2 as (SELECT query2) ....] SELECT query |
Effect:
|
|
This query finds John Smith: (SELECT * FROM employee WHERE fname='John' AND lname='Smith') |
|
|
|
Solution:
First, we find all male employees: R1 = (select * from employee where sex='M') |
|