不使用JOIN如何实现关键词SQL连接? + i1 l4 ~( Y1 @这并非真正必要,但我认为通过这样做,我可以更好地理解联系的实际作用。 7 v5 [9 s6 \+ n ) V4 H* J$ n: A7 E解决方案: % m3 H. G. Q, }$ o3 H
基本的INNER JOIN易于实现。3 ~7 h p& i, u2 U' a! Q
SELECT L.XCol,R.YColFROM LeftTable AS LINNER JOIN RightTable AS RON L.IDCol=R.IDCol;等效于: : p4 C/ a- f# s' E- O0 q# VSELECT L.XCol,R.YColFROM LeftTable AS L,RightTable AS RWHERE L.IDCol=R.IDCol;扩展到LEFT / RIGHT / FULL OUTER JOIN,你只需要正确列出不匹配的行和行NULL联合到以前INNER JOIN。2 Q H, K8 y7 R" u$ x; U% N7 x
添加左外连接: ( t& e, i" R4 }( V' }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)添加正确的外部连接:; g3 ]! U, p; ]- H+ b0 y0 [( Y5 U
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,请同时添加以上两项。