不使用JOIN如何实现关键词SQL连接?! f$ P& {+ i# k$ U5 Q+ P
这并非真正必要,但我认为通过这样做,我可以更好地理解联系的实际作用。 , o) o( K3 i$ u5 R " P! A2 Z! N0 F5 ?6 e; h解决方案: % R' O7 s- j3 n5 n I6 I2 y 基本的INNER JOIN易于实现。: M1 Y% H9 x7 d
SELECT L.XCol,R.YColFROM LeftTable AS LINNER JOIN RightTable AS RON L.IDCol=R.IDCol;等效于: j6 Z1 L- F. y- `6 \$ g7 f/ m9 xSELECT L.XCol,R.YColFROM LeftTable AS L,RightTable AS RWHERE L.IDCol=R.IDCol;扩展到LEFT / RIGHT / FULL OUTER JOIN,你只需要正确列出不匹配的行和行NULL联合到以前INNER JOIN。/ m1 R# G& K/ W/ v, j
添加左外连接:5 N& K1 \: e2 p$ q
UNION ALLSELECT L.XCol,NULL /* cast the NULL as needed */FROM LeftTable AS LWHERE NOT EXISTS SELECT * FROM RightTable AS R WHERE L.IDCol=R.IDCol)添加正确的外部连接: ' X8 E& w$ s2 ~UNION ALLSELECT NULL,R.YCol /* cast the NULL as needed */FROM RightTable AS RWHERE NOT EXISTS SELECT * FROM LeftTable AS L WHERE L.IDCol=R.IDCol)对于FULL OUTER JOIN,请同时添加以上两项。