|
|
Project.essn refers the the essn attribute in Project relation Dependent.essn refers the the essn attribute in Dependent relation |
|
Solution:
Find out who has a daughter named Alice: SELECT essn FROM dependent WHERE name='Alice' |
|
|
|
Syntax to specify an alias:
SELECT FROM R alias1 , R alias2 , .... WHERE ... |
Meaning:
|
|
|
Solution:
List the employee's name and his/her supervisor SSN: SELECT fname, lname, superssn FROM employee |
SELECT e.fname, e.lname, m.fname, m.lname FROM employee e, employee m WHERE e.superssn = m.ssn; Output: +--------+---------+--------+---------+ | fname | lname | fname | lname | +--------+---------+--------+---------+ | John | Smith | Frankl | Wong | | Ramesh | Narayan | Frankl | Wong | | Joyce | English | Frankl | Wong | | Alicia | Zelaya | Jennif | Wallace | | Ahmad | Jabbar | Jennif | Wallace | | Frankl | Wong | James | Borg | | Jennif | Wallace | James | Borg | +--------+---------+--------+---------+ |
The name (title) of the attributes are not very meaningful (in fact: ambigious)
SELECT e.fname EmpFN, e.lname EmpLN, m.fname SupFN, m.lname SupFN FROM employee e, employee m WHERE e.superssn = m.ssn; Output: +--------+---------+--------+---------+ | EmpFN | EmpLN | SupFN | SupFN | +--------+---------+--------+---------+ | John | Smith | Frankl | Wong | | Ramesh | Narayan | Frankl | Wong | | Joyce | English | Frankl | Wong | | Alicia | Zelaya | Jennif | Wallace | | Ahmad | Jabbar | Jennif | Wallace | | Frankl | Wong | James | Borg | | Jennif | Wallace | James | Borg | +--------+---------+--------+---------+ |