Rewriting SQL Queries
Complicated by interaction of:
NULLs, duplicates, aggregation, subqueries.
Guideline: Use only one “query block”, if possible.
SELECT DISTINCT *
FROM Sailors S
WHERE S.sname IN
(SELECT Y.sname
FROM YoungSailors Y)
SELECT DISTINCT S.*
FROM Sailors S,
YoungSailors Y
WHERE S.sname = Y.sname
SELECT *
FROM Sailors S
WHERE S.sname IN
(SELECT DISTINCT Y.sname
FROM YoungSailors Y)
SELECT S.*
FROM Sailors S,
YoungSailors Y
WHERE S.sname = Y.sname
Not always possible ...
=
=
Previous slide
Next slide
Back to first slide
View graphic version