CHAPTER 12
12.1
ANATURAL JOINB: IllegalAINTERSECTB: Illegal SELECT * FROMANATURAL JOINB: Legal SELECT * FROMAINTERSECTB: Illegal SELECT * FROM (ANATURAL JOINB) : Legal SELECT * FROM (AINTERSECTB) : Illegal SELECT * FROM ( SELECT * FROMAINTERSECT SELECT * FROMB) : Illegal SELECT * FROM (ANATURAL JOINB) ASC: Illegal SELECT * FROM (AINTERSECTB) ASC: Illegal TABLEANATURAL JOIN TABLEB: Illegal TABLEAINTERSECT TABLEB: Legal SELECT * FROMAINTERSECT SELECT * FROMB: Legal ( SELECT * FROMA) INTERSECT ( SELECT * FROMB) : Legal ( SELECT * FROMA) ASAAINTERSECT ( SELECT * FROMB) ASBB: Illegal
You were also asked what you conclude from this exercise. One thing I conclude is that the rules are very difficult to remember (to say the least). In particular, SQL expressions involving INTERSECT can’t always be transformed straightforwardly into their JOIN counterparts. I remark also that if we replace INTERSECT by NATURAL JOIN in the last two expressions, then the legal one becomes illegal and vice versa! That’s because, believe it or not, the expressions
( SELECT * FROM A )and
( SELECT * FROM B )are considered to be subqueries in the context of NATURAL JOIN but not that of INTERSECT. (In other words, a subquery is a SELECT expression enclosed in parentheses, loosely speaking, but a SELECT expression enclosed in parentheses isn’t necessarily a subquery.)
12.2 The effects are as follows: The second expression was previously illegal but becomes ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access