usingÔÚsqlÖÐÊÇʲôÒâ˼
using Òªº¦×ÖÔÚ sql ÖÐÓÃÓÚÅþÁ¬¾ßÓÐÅäºÏÁÐµÄ±í£¬ÆäÖ÷Òª×÷ÓðüÀ¨£ºÅþÁ¬±í£ºusing ¿ÉÅþÁ¬Á½¸ö»ò¶à¸ö±í£¬ÒÔÅÌÎÊ»ò²Ù×÷ÆäÊý¾Ý¡£Ö¸¶¨ÅþÁ¬Ìõ¼þ£ºusing ¿ÉÖ¸¶¨ÅþÁ¬Ìõ¼þ£¬ÓÃÓÚ½ÏÁ¿¹«¹²ÁÐÖеÄÖµ£¬´Ó¶ø¾öÒéÅþÁ¬ÄÄЩÐС£
USING ÔÚ SQL ÖеļÄÒå
USING Òªº¦×ÖÔÚ SQL ÖÐÓÃÀ´ÅþÁ¬±í²¢Ö¸¶¨ÅþÁ¬Ìõ¼þ¡£ÆäÖ÷Òª×÷ÓÃÊÇ:
ÅþÁ¬±í
USING Ö÷ÒªÓÃÓÚÅþÁ¬¾ßÓÐÅäºÏÁÐµÄ±í¡£ËüÔÊÐíÄú½«Á½¸ö»ò¶à¸ö±íÅþÁ¬µ½Ò»Æð£¬ÒÔ±ãÅÌÎÊ»ò²Ù×÷ÆäÊý¾Ý¡£
Óï·¨
USING Óï·¨µÄ»ù±¾ÐÎʽΪ:
SELECT column_list FROM table1 INNER JOIN table2 USING (common_column)
µÇ¼ºó¸´ÖÆ
ÆäÖÐ:
table1 ºÍ table2 ÊÇÒªÅþÁ¬µÄ±í
common_column ÊÇÁ½¸ö±íÖоßÓÐÏàͬÊý¾ÝÀàÐ͵Ĺ«¹²ÁÐ
INNER JOIN Ö¸¶¨ÄÚÅþÁ¬ÀàÐÍ£¬½ö·µ»Ø¾ßÓÐÆ¥ÅäÖµµÄÐеļͼ
ÅþÁ¬Ìõ¼þ
USING Òªº¦×Ö¿ÉÒÔÖ¸¶¨ÅþÁ¬Ìõ¼þ£¬ÒÔÈ·¶¨ÅþÁ¬ÄÄЩÐС£ËüʵÖÊÉÏÊÇ WHERE ×Ó¾äµÄ¼òдÐÎʽ£¬ÓÃÓÚ½ÏÁ¿¹«¹²ÁÐÖеÄÖµ¡£
ʾÀý
ÀýÈ磬˼Á¿ÒÔÏ Customer ºÍ Order ±í:
CREATE TABLE Customer ( customer_id INT PRIMARY KEY, name VARCHAR(255) ); CREATE TABLE Order ( order_id INT PRIMARY KEY, customer_id INT, product VARCHAR(255), quantity INT, FOREIGN KEY (customer_id) REFERENCES Customer(customer_id) );
µÇ¼ºó¸´ÖÆ
Òª´ÓÕâÁ½¸ö±íÖÐÑ¡ÔñÊý¾Ý£¬Äú¿ÉÒÔʹÓà USING ÅþÁ¬:
SELECT * FROM Customer INNER JOIN Order USING (customer_id) WHERE quantity > 5;
µÇ¼ºó¸´ÖÆ
´ËÅÌÎʽ«·µ»ØËùÓйºÖÃÊýÄ¿´óÓÚ 5 µÄ¿Í»§ºÍ¶©µ¥¼Í¼¡£
ÒÔÉϾÍÊÇusingÔÚsqlÖÐÊÇʲôÒâ˼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡