mysqlÖÐÄÚÅþÁ¬ÅÌÎʵÄonºóÃæÔõôд
inner join ºóÃæµÄ on Óï¾äÓÃÓÚÖ¸¶¨ÓÃÓÚ½ÏÁ¿ºÍÆ¥Åä±íµÄÁС£Ó﷨Ϊ£ºon = ¡£ÆäËûÒªµã£º1. ÔËËã·û¿ÉÌ滻Ϊ >¡¢= ºÍ
ÔÚ MySQL ÖУ¬INNER JOIN ºóÃæµÄ ON Óï¾äÔõÑùд
INNER JOIN ÊÇ MySQL ÖÐÒ»ÖÖ³£¼ûµÄ±íÅþÁ¬ÀàÐÍ£¬ÓÃÓÚ½«Á½¸ö»ò¶à¸ö±íÖеÄÐкϲ¢ÎªÒ»¸öЧ¹û¼¯£¬ÆäÖоßÓÐÆ¥ÅäÖµµÄÐеÄÐн«ºÏ²¢¡£ON Óï¾äÖ¸¶¨ÓÃÓÚ½ÏÁ¿ºÍÆ¥Åä±íµÄÁС£
ON Óï¾äµÄÓï·¨£º
ON =
µÇ¼ºó¸´ÖÆ
ÆäÖУº
ºÍÊǼÓÈë½ÏÁ¿µÄÁ½¸öÁÐ
=ÊǽÏÁ¿ÔËËã·û£¬ÌåÏÖÁ½ÁеÄÖµ±ØÐèÏàµÈ²Å»ª¾ÙÐÐÆ¥Åä
ʾÀý£º
¼ÙÉèÎÒÃÇÓÐÁ½¸ö±í£ºcustomers ºÍ orders£¬²¢ÇÒÎÒÃÇÒªÕÒ³öËùÓÐÒÑ϶©µ¥µÄ¿Í»§¡£¿ÉÒÔʹÓÃÒÔÏ INNER JOIN ÅÌÎÊ£º
SELECT * FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id;
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öÀý×ÓÖУ¬ON Óï¾ä customers.customer_id = orders.customer_id Ö¸¶¨ÁËÁ½¸ö±íÔÚ¿Í»§ ID ÁÐÉϾÙÐÐÆ¥Åä¡£ÕâÒâζ×ÅֻѡÔñÄÇЩÔÚÁ½¸ö±íÖж¼ÓÐÏàͬ¿Í»§ ID µÄÐС£
ÆäËûÒªµã£º
¿ÉÒÔÔÚ ON Óï¾äÖÐʹÓÃÆäËû½ÏÁ¿ÔËËã·û£¬ÀýÈç >¡¢= ºÍ
¿ÉÒÔʹÓöà¸ö ON ×Ó¾äÀ´Ö¸¶¨¶à¸öÆ¥ÅäÌõ¼þ¡£
ÈôÊDz»Ö¸¶¨ ON Óï¾ä£¬ÔòĬÈÏÇéÐÎÏ»áʹÓõѿ¨¶û»ýÅþÁ¬£¬Õ⽫µ¼ÖÂËùÓÐÐеÄËùÓпÉÄÜ×éºÏ¡£
ÒÔÉϾÍÊÇmysqlÖÐÄÚÅþÁ¬ÅÌÎʵÄonºóÃæÔõôдµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡