W4 DBMS Chapter07
W4 DBMS Chapter07
Nested queries,
Joined tables
is present in the inner query's result. The final result will have rows that
satisfy the IN condition.
The NOT IN operator checks if a column value in the outer query's result
is not present in the inner query's result. The final result will have rows that
satisfy the NOT IN condition.
The ALL operator compares a value of the outer query's result with all the
values of the inner query's result and returns the row if it matches all the
values.
The ANY operator compares a value of the outer query's result with all the
inner query's result values and returns the row if there is a match with any
value.
Copyright © 2017 Ramez Elmasri and Shamkant B. Navathe Slide 7- 10
Co-related Nested Queries
In co-related nested queries, the inner query uses
the values from the outer query so that the inner
query is executed for every row processed by the
outer query.
The co-related nested queries run slowly because
the inner query is executed for every row of the outer
query's result.
We can write a nested query in SQL by nesting
SELECT statement within another SELECT
statement.
The outer SELECT statement uses the result of the
inner SELECT statement for processing. Slide 7- 11
Copyright © 2017 Ramez Elmasri and Shamkant B. Navathe
Nested Queries Examples (Independent)
Awards
id employee_id award_date
1 1 2022-04-01
2 3 2022-05-01
id name
2 Perice Mundford
4 Garwood Saffen
5 Faydra Beaves
id name
1 Augustine Hammond
3 Cassy Delafoy
Copyright © 2017 Ramez Elmasri and Shamkant B. Navathe Slide 7- 15
id name salary role Independent
5 Faydra Beaves 50000 Developer Nested
Queries
Unique
constraint
EmployeeID Name CourseID Year
77505 Alan SC110 2017
INNER JOIN
If no matching tuple
Fill in with NULL values for attributes of right table
RIGHT OUTER JOIN
Every tuple in right table must appear in result
If no matching tuple
Fill in with NULL values for attributes of left table