sql語法規范join
❶ 奼係QL璇鍙ラ噷闈join鐨勭敤娉,奼備緥瀛愬強璁茶В銆
join 鐢ㄤ簬鏍規嵁涓や釜鎴栧氫釜琛ㄤ腑鐨勫垪涔嬮棿鐨勫叧緋伙紝浠庤繖浜涜〃涓鏌ヨ㈡暟鎹銆
JOIN: 濡傛灉琛ㄤ腑鏈夎嚦灝戜竴涓鍖歸厤錛屽垯榪斿洖琛
LEFT JOIN: 鍗充嬌鍙寵〃涓娌℃湁鍖歸厤錛屼篃浠庡乏琛ㄨ繑鍥炴墍鏈夌殑琛
RIGHT JOIN: 鍗充嬌宸﹁〃涓娌℃湁鍖歸厤錛屼篃浠庡彸琛ㄨ繑鍥炴墍鏈夌殑琛
FULL JOIN: 鍙瑕佸叾涓涓涓琛ㄤ腑瀛樺湪鍖歸厤錛屽氨榪斿洖琛
SQL INNER JOIN 鍏抽敭瀛
鍦ㄨ〃涓瀛樺湪鑷沖皯涓涓鍖歸厤鏃訛紝INNER JOIN 鍏抽敭瀛楄繑鍥炶屻
INNER JOIN 鍏抽敭瀛楄娉
SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name
娉ㄩ噴錛欼NNER JOIN 涓 JOIN 鏄鐩稿悓鐨勩
SQL LEFT JOIN 鍏抽敭瀛
LEFT JOIN 鍏抽敭瀛椾細浠庡乏琛 (table_name1) 閭i噷榪斿洖鎵鏈夌殑琛岋紝鍗充嬌鍦ㄥ彸琛 (table_name2) 涓娌℃湁鍖歸厤鐨勮屻
LEFT JOIN 鍏抽敭瀛楄娉
SELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2
ON table_name1.column_name=table_name2.column_name
SQL RIGHT JOIN 鍏抽敭瀛
RIGHT JOIN 鍏抽敭瀛椾細鍙寵〃 (table_name2) 閭i噷榪斿洖鎵鏈夌殑琛岋紝鍗充嬌鍦ㄥ乏琛 (table_name1) 涓娌℃湁鍖歸厤鐨勮屻
RIGHT JOIN 鍏抽敭瀛楄娉
SELECT column_name(s)
FROM table_name1
RIGHT JOIN table_name2
ON table_name1.column_name=table_name2.column_name
娉ㄩ噴錛氬湪鏌愪簺鏁版嵁搴撲腑錛 RIGHT JOIN 縐頒負 RIGHT OUTER JOIN銆
SQL FULL JOIN 鍏抽敭瀛
鍙瑕佸叾涓鏌愪釜琛ㄥ瓨鍦ㄥ尮閰嶏紝FULL JOIN 鍏抽敭瀛楀氨浼氳繑鍥炶屻
FULL JOIN 鍏抽敭瀛楄娉
SELECT column_name(s)
FROM table_name1
FULL JOIN table_name2
ON table_name1.column_name=table_name2.column_name
娉ㄩ噴錛氬湪鏌愪簺鏁版嵁搴撲腑錛 FULL JOIN 縐頒負 FULL OUTER JOIN銆
http://www.w3school.com.cn/sql/sql_join.asp