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