|
SELECT essn, name FROM dependent +-----------+-----------+ | essn | name | +-----------+-----------+ | 333445555 | Alice | | 333445555 | Theodore | | 333445555 | Joy | | 987654321 | Abner | | 123456789 | Micheal | | 123456789 | Alice | | 123456789 | Elizabeth | +-----------+-----------+ |
(but we do need a correlated inner query):
SELECT fname, lname FROM employee E WHERE #{dependents of employee E} >= 2 |
This is just to show you there is more than one way to skin a cat...
|
Consider the employees: +-----------+--------+---------+-----+ | ssn | fname | lname | dno | +-----------+--------+---------+-----+ | 888665555 | James | Borg | 1 | | 999887777 | Alicia | Zelaya | 4 | | 987654321 | Jennif | Wallace | 4 | | 987987987 | Ahmad | Jabbar | 4 | | 123456789 | John | Smith | 5 | | 333445555 | Frankl | Wong | 5 | | 666884444 | Ramesh | Narayan | 5 | | 453453453 | Joyce | English | 5 | +-----------+--------+---------+-----+ |
(Again, we use a correlated inner query):
SELECT dname FROM department D WHERE #{employees in department D} >= 3 |
So there are different ways to solve a query...