-- Practice Final Solutions
BY TOAN TRAN, SUDHANSHU DANGI, AND PARMEET SINGH
6) Define the following and give an example: (a) Left Outer Join,.(b) nested for Loop query semantics. (c) correlated subquery.
A)LEFT OUTER JOIN is the dangling tuples of the left argument R are pad with (NIL) and add to the result.
EX: U = A(1, 4, 7), B(2, 5, 8), C(3, 6, 9)
V = B(2, 2, 6), C(3, 3, 7), D(10, 11, 12)
The LEFT OUTER JOIN of U & V is A(1, 1, 4, 7), B(2, 2, 5, 8), C(3, 3, 6, 9), D(10, 11, NIL, NIL)
B) Nested for loop query semantics is used when there are several tuple variables in which each variable range over the tuples of their respective relation. The FOR clause assign the tuple expression to the tuple variable to decide whether the WHERE clause is true, then we produce a tuple consisting of the values of the expression followed by a SELECT clause.
EX:
LET the tuple variables in the from-clause range over relations R1,R2,...,Rn;
FOR each tuple t1 in relation R1 DO
...something
FOR each tuple t2 in relation R2 DO
FOR each tuple tn in relation Rn DO
IF the where-clause is satisfied when the values from t1,t2,... ,tn are substituted for all attribute references THEN
evaluate the expressions of the select-clause according to t1,t2,... ,tn andproducethe tuple of values that results.
C) Correlated subquery is a nested subqueries requires the subquery to be evaluated many times, once for each assignment of a value to some term in the subquery that comes from a tuple variable outside the subquery.
EX: Given this relation.
Movies(title, year, length, genre, studioName, producerC#)
We want to find the titles that have been used for two or more movies. We start with an outer query that looks at all tuples in the relation.
SELECT title
FROM Movies Old
WHERE year < ANY
(SELECT year
FROM Movies
WHERE title = Old.title);
(
Edited: 2019-12-10)
BY TOAN TRAN, SUDHANSHU DANGI, AND PARMEET SINGH
6) Define the following and give an example: (a) Left Outer Join,.(b) nested for Loop query semantics. (c) correlated subquery.
A)LEFT OUTER JOIN is the dangling tuples of the left argument R are pad with (NIL) and add to the result.
EX: U = A(1, 4, 7), B(2, 5, 8), C(3, 6, 9)
V = B(2, 2, 6), C(3, 3, 7), D(10, 11, 12)
The LEFT OUTER JOIN of U & V is A(1, 1, 4, 7), B(2, 2, 5, 8), C(3, 3, 6, 9), D(10, 11, NIL, NIL)
B) Nested for loop query semantics is used when there are several tuple variables in which each variable range over the tuples of their respective relation. The FOR clause assign the tuple expression to the tuple variable to decide whether the WHERE clause is true, then we produce a tuple consisting of the values of the expression followed by a SELECT clause.
EX:
LET the tuple variables in the from-clause range over relations R1,R2,...,Rn;
FOR each tuple t1 in relation R1 DO
...something
FOR each tuple t2 in relation R2 DO
FOR each tuple tn in relation Rn DO
IF the where-clause is satisfied when the values from t1,t2,... ,tn are substituted for all attribute references THEN
evaluate the expressions of the select-clause according to t1,t2,... ,tn andproducethe tuple of values that results.
C) Correlated subquery is a nested subqueries requires the subquery to be evaluated many times, once for each assignment of a value to some term in the subquery that comes from a tuple variable outside the subquery.
EX: Given this relation.
Movies(title, year, length, genre, studioName, producerC#)
We want to find the titles that have been used for two or more movies. We start with an outer query that looks at all tuples in the relation.
SELECT title
FROM Movies Old
WHERE year < ANY
(SELECT year
FROM Movies
WHERE title = Old.title);