select attribute-list from relation-list where condition |
|
|
select fname, lname
from employee
where dno = 5
The condition "dno=5" is applied
to the set of employee tuples
|
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:
|
| Find the fname and lname of employees whose SSN is 123456789 or 333445555 |
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:
|
|
SELECT fname, lname
FROM employee
WHERE ssn = ANY ('111-11-1111', '222-22-2222')
|
meaning:
|
In other words:
|
SELECT fname, lname
FROM employee
WHERE ssn != ALL ('111-11-1111', '222-22-2222')
|
meaning:
|
In other words:
|
x = ANY ( set of values )
is the same as:
x IN ( set of values )
|
|
x = ALL ( 1, 2 ) is always FALSE !!!
// Try: x = 0 --> 0 != 1, so false
// Try: x = 1 --> 1 != 2, so false
// Try: x = 2 --> 2 != 1, so false
// Try: x = 3 --> 3 != 1, so false
// And so on...
|
|
exists ( set of values )
|
meaning:
|
atomic-value IS NULL
|
SELECT *
FROM employee
WHERE salary IS NULL
|
|
|
| Find fname and lname of employees whose last name start with an 'S' |
Solution:
SELECT fname, lname
FROM employee
WHERE lname LIKE 'S%'
|
|
|
|