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

mysqlÖÐonµÄÓ÷¨

on ×Ó¾äÓÃÓÚÖ¸¶¨ join ²Ù×÷ÖнÏÁ¿ºÍºÏ²¢Á½¸ö±íµÄÐеÄÌõ¼þ£¬°üÀ¨ÄÚÅþÁ¬¡¢×óÍâÅþÁ¬¡¢ÓÒÍâÅþÁ¬ºÍÈ«ÍâÅþÁ¬¡£on Ìõ¼þֻʹÓÃÏàµÈ½ÏÁ¿£¬¿ÉÒÔʹÓöà¸öÌõ¼þÖ¸¶¨¸üÖØ´óµÄÅþÁ¬¹æÔò£¬²¢¿ÉÓëÆäËû join ÀàÐÍÒ»ÆðʹÓá£

MySQL ÖÐ ON µÄÓ÷¨

ON ×Ó¾ä¸ÅÊö

ON ×Ó¾äÓÃÓÚÖ¸¶¨ÔÚ JOIN ²Ù×÷ÖнÏÁ¿ºÍºÏ²¢Á½¸ö±íµÄÐеÄÌõ¼þ¡£

Óï·¨

ON ±í1.ÁÐÃû = ±í2.ÁÐÃû

µÇ¼ºó¸´ÖÆ

Ó÷¨

ÄÚÅþÁ¬ (INNER JOIN)£ºÖ»·µ»ØÁ½¸ö±íÖÐÆ¥ÅäµÄÐС£

×óÍâÅþÁ¬ (LEFT OUTER JOIN)£º·µ»Ø×ó±íÖеÄËùÓÐÐУ¬ÒÔ¼°ÈκÎÔÚÓÒ±íÖÐÆ¥ÅäµÄÐС£ÈôÊÇÓÒ±íÖÐûÓÐÆ¥Å䣬Ôò·µ»Ø NULL¡£

ÓÒÍâÅþÁ¬ (RIGHT OUTER JOIN)£ºÓë×óÍâÅþÁ¬ÀàËÆ£¬µ«·µ»ØÓÒ±íÖеÄËùÓÐÐС£

È«ÍâÅþÁ¬ (FULL OUTER JOIN)£º·µ»ØÁ½¸ö±íÖеÄËùÓÐÐУ¬ÎÞÂÛÊÇ·ñÆ¥Åä¡£

ʾÀý

ÄÚÅþÁ¬£º

SELECT * FROM ±í1
INNER JOIN ±í2 ON ±í1.id = ±í2.id;

µÇ¼ºó¸´ÖÆ

×óÍâÅþÁ¬£º

SELECT * FROM ±í1
LEFT OUTER JOIN ±í2 ON ±í1.id = ±í2.id;

µÇ¼ºó¸´ÖÆ

ÓÒÍâÅþÁ¬£º

SELECT * FROM ±í1
RIGHT OUTER JOIN ±í2 ON ±í1.id = ±í2.id;

µÇ¼ºó¸´ÖÆ

È«ÍâÅþÁ¬£º

SELECT * FROM ±í1
FULL OUTER JOIN ±í2 ON ±í1.id = ±í2.id;

µÇ¼ºó¸´ÖÆ

×¢ÖØÊÂÏî

ON Ìõ¼þÖ»ÄÜʹÓÃÏàµÈ½ÏÁ¿£¨=£©¡£

¿ÉÒÔʹÓöà¸ö ON Ìõ¼þÀ´Ö¸¶¨¸üÖØ´óµÄÅþÁ¬¹æÔò¡£

ON ×Ó¾ä¿ÉÒÔÓëÆäËû JOIN ÀàÐÍ£¨Èç CROSS JOIN¡¢NATURAL JOIN£©Ò»ÆðʹÓá£

ÒÔÉϾÍÊÇmysqlÖÐonµÄÓ÷¨µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ