select attribute-list from relation-list where condition |
|
|
select ssn, fname, lname, dno from employee +-----------+--------+---------+-----+ | ssn | fname | lname | dno | +-----------+--------+---------+-----+ | 123456789 | John | Smith | 5 | | 333445555 | Frankl | Wong | 5 | | 999887777 | Alicia | Zelaya | 4 | | 987654321 | Jennif | Wallace | 4 | | 666884444 | Ramesh | Narayan | 5 | | 453453453 | Joyce | English | 5 | | 987987987 | Ahmad | Jabbar | 4 | | 888665555 | James | Borg | 1 | +-----------+--------+---------+-----+ |
select fname, lname from employee, department where dno = 5 and dname = 'Research' The condition "dno=5 and dname='Research'" is applied to the tuples in the cartesian product employee × department |
|
All I want to say is:
|
(1) where salary > 40000 // attr name and a constant (2) where dnumber = dno // 2 attr names and sex = 'F' // attr name and a (string) constant |
atomic-value IN ( set of values ) |
meaning:
|
|
Solution:
SELECT fname, lname FROM employee WHERE ssn IN ('123456789', '333445555'); |
atomic-value NOT IN ( set of values ) |
meaning:
|
Find the fname and lname of employees whose SSN is not equal to 123456789 or 333445555 |
Solution:
SELECT fname, lname FROM employee WHERE ssn NOT IN ('123456789', '333445555'); |
|
atomic-value RelationalOperator any ( set of values ) |
meaning:
|
SELECT fname, lname FROM employee WHERE salary >= ANY ( 30000, 50000 ) |
Result of this query:
|
|
atomic-value RelationalOperator all ( set of values ) |
meaning:
|
SELECT fname, lname FROM employee WHERE salary >= ALL ( 30000, 50000 ) |
Result of this query:
|
|
exists ( set of values ) |
meaning:
|
atomic-value IS NULL |
SELECT * FROM employee WHERE salary IS NULL |
|
|
|
Solution:
SELECT fname, lname FROM employee WHERE lname LIKE 'S%' |
|
|
|