×ðÁú¿­Ê±¹ÙÍøµÇ¼

sqlÖеÄ×óÅþÁ¬ºÍÓÒÅþÁ¬ÊÇʲô

sql ÖеÄ×óÅþÁ¬ºÍÓÒÅþÁ¬ÊÇÁ½ÖÖÅþÁ¬±íµÄ·½·¨£º×óÅþÁ¬£º±£´æ×ó±íËùÓÐÐУ¬×ÝÈ»ÓÒ±íûÓÐÆ¥ÅäÐУ¬ÓÒ±í×Ö¶ÎΪ¿Õ¡£ÓÒÅþÁ¬£º±£´æÓÒ±íËùÓÐÐУ¬×ÝÈ»×ó±íûÓÐÆ¥ÅäÐУ¬×ó±í×Ö¶ÎΪ¿Õ¡£

SQL ÖеÄ×óÅþÁ¬ºÍÓÒÅþÁ¬

ÔÚ SQL ÖУ¬ÅþÁ¬ÊÇδÀ´×ÔÁ½¸ö»ò¸ü¶à±íµÄÐÐ×éºÏÔÚÒ»ÆðµÄÀú³Ì¡£×óÅþÁ¬ºÍÓÒÅþÁ¬ÊÇÅþÁ¬±íµÄÁ½ÖÖÌض¨ÀàÐÍ¡£

×óÅþÁ¬

±£´æ×ó±íÖеÄËùÓÐÐУ¬×ÝÈ»ÔÚÓÒ±íÖÐûÓÐÆ¥ÅäµÄÐС£

¹ØÓÚÓÒ±íÖÐûÓÐÆ¥ÅäÐеÄ×ó±íÐУ¬ÓÒ±íÖеÄ×ֶν«ÏÔʾΪ NULL¡£

ÓÒÅþÁ¬

±£´æÓÒ±íÖеÄËùÓÐÐУ¬×ÝÈ»ÔÚ×ó±íÖÐûÓÐÆ¥ÅäµÄÐС£

¹ØÓÚ×ó±íÖÐûÓÐÆ¥ÅäÐеÄÓÒ±íÐУ¬×ó±íÖеÄ×ֶν«ÏÔʾΪ NULL¡£

Óï·¨

×óÅþÁ¬£º

SELECT *
FROM ×ó±í
LEFT JOIN ÓÒ±í ON ×ó±íÀ¸ = ÓÒ±íÀ¸;

µÇ¼ºó¸´ÖÆ

ÓÒÅþÁ¬£º

SELECT *
FROM ÓÒ±í
RIGHT JOIN ×ó±í ON ×ó±íÀ¸ = ÓÒ±íÀ¸;

µÇ¼ºó¸´ÖÆ

ʾÀý

˼Á¿ÒÔÏÂÁ½¸ö±í£º

×ó±í£º
+----+--------+
| id | Ãû³Æ    |
+----+--------+
| 1  | John    |
| 2  | Mary    |
+----+--------+

ÓÒ±í£º
+----+---------+
| id | µØµã    |
+----+---------+
| 1  | Main St |
| 3  | Oak Ave |
+----+---------+

µÇ¼ºó¸´ÖÆ

×óÅþÁ¬£º

SELECT *
FROM ×ó±í
LEFT JOIN ÓÒ±í ON ×ó±í.id = ÓÒ±í.id;

µÇ¼ºó¸´ÖÆ

Êä³ö£º

+----+--------+---------+
| id | Ãû³Æ    | µØµã    |
+----+--------+---------+
| 1  | John    | Main St |
| 2  | Mary    | NULL    |
+----+--------+---------+

µÇ¼ºó¸´ÖÆ

ÓÒÅþÁ¬£º

SELECT *
FROM ÓÒ±í
RIGHT JOIN ×ó±í ON ×ó±í.id = ÓÒ±í.id;

µÇ¼ºó¸´ÖÆ

Êä³ö£º

+----+---------+--------+
| id | µØµã    | Ãû³Æ    |
+----+---------+--------+
| 1  | Main St | John    |
| 3  | Oak Ave | NULL    |
+----+---------+--------+

µÇ¼ºó¸´ÖÆ

ÒÔÉϾÍÊÇsqlÖеÄ×óÅþÁ¬ºÍÓÒÅþÁ¬ÊÇʲôµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ