sqlÖÐusingÊÇʲôÒâ˼
sql ÖÐ using Òªº¦×ÖÓÃÓÚÅþÁ¬±í£¬Í¨¹ýÖ¸¶¨Ò»¸ö¼ÓÈëÅþÁ¬µÄÁÐÀ´Ö¸¶¨ÅþÁ¬Ìõ¼þ¡£ËüÖ»ÔÊÐí°´Ò»¸öÁÐÅþÁ¬±í£¬Òò´Ëµ± join Ìõ¼þÉæ¼°Ò»¸öÁÐʱ£¬ËüÌṩÁ˾«Á·Ò׶ÁµÄÓï·¨¡£
SQL ÖÐ USING µÄ¼ÄÒå
ÔÚ SQL ÖУ¬USING Òªº¦×ÖÓÃÓÚÅþÁ¬±í£¬ÌØÊâÊÇÔÚ JOIN ²Ù×÷ÖУ¬ËüÖ¸¶¨¼ÓÈëÅþÁ¬µÄÁС£
ʹÓ÷½·¨
USING ×Ó¾äµÄÓï·¨ÈçÏ£º
SELECT ... FROM table1 JOIN table2 USING (column_name)
µÇ¼ºó¸´ÖÆ
ÆäÖУº
table1 ºÍ table2 ÊÇÒªÅþÁ¬µÄ±í¡£
column_name ÊÇÅþÁ¬Á½±íʱҪʹÓõÄÁÐÃû¡£
×÷ÓÃ
USING ×Ó¾äµÄ×÷ÓÃÊÇÖ¸¶¨ÅþÁ¬Ìõ¼þ£¬Ëüͨ¹ýÆ¥ÅäÁ½¸ö±íÖоßÓÐÏàֵͬµÄÖ¸¶¨ÁÐÀ´ÅþÁ¬±í¡£ÕâÒâζ×ÅÖ¸¶¨µÄÁÐÔÚÁ½¸ö±íÖж¼ÊÇÖ÷¼ü»òΨһ¼ü¡£
ʾÀý
ÀýÈ磬ÒÔÏÂÅÌÎÊʹÓà USING ×Ӿ佫 Customers ±íºÍ Orders ±íÅþÁ¬ÆðÀ´£¬²¢½« customer_id ÁÐÓÃ×÷ÅþÁ¬Ìõ¼þ£º
SELECT * FROM Customers JOIN Orders USING (customer_id) WHERE customer_name = 'John Doe';
µÇ¼ºó¸´ÖÆ
Óë ON ×Ó¾äµÄÇø±ð
USING ×Ó¾äÓë ON ×Ó¾äºÜÊÇÏàËÆ£¬ËüÃǶ¼ÓÃÓÚÖ¸¶¨ JOIN Ìõ¼þ¡£È»¶ø£¬USING ×Ó¾äÓÐÒ»¸öÖ÷ÒªÇø±ð£º
USING ×Ó¾äÖ»ÔÊÐí°´Ò»¸öÁÐÅþÁ¬±í£¬¶ø ON ×Ó¾ä¿ÉÒÔ°´¶à¸ö±í´ïʽÅþÁ¬±í¡£
µ± JOIN Ìõ¼þÉæ¼°Ò»¸öÁÐʱ£¬USING ×Ó¾ä¿ÉÒÔÌṩ¸ü¾«Á·¡¢¸üÒ׶ÁµÄÓï·¨¡£
ÒÔÉϾÍÊÇsqlÖÐusingÊÇʲôÒâ˼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡