SQL LEFT JOIN ¹Ø¼ü×Ö
SQL LEFT JOIN ¹Ø¼ü×Ö
SQL LEFT JOIN ¹Ø¼ü×Ö
LEFT JOIN ¹Ø¼ü×Ö»á´Ó×ó±í (table_name1) ÄÇÀï·µ»ØËùÓеÄÐУ¬¼´Ê¹ÔÚÓÒ±í (table_name2) ÖÐûÓÐÆ¥ÅäµÄÐС£
LEFT JOIN ¹Ø¼ü×ÖÓï·¨
SELECT column_name(s)
from table_name1
LEFT JOIN table_name2
ON table_name1.column_name=table_name2.column_name
×¢ÊÍ£ºÔÚijЩÊý¾Ý¿âÖУ¬ LEFT JOIN ³ÆΪ LEFT OUTER JOIN¡£
ÔʼµÄ±í (ÓÃÔÚÀý×ÓÖеÄ)£º
"Persons" 񡜧
Id_PLastNameFirstNameAddressCity
1
Adams
John
Oxford Street
London
2
Bush
George
Fifth Avenue
New York
3
Carter
Thomas
Changan Street
Beijing
"Orders" 񡜧
Id_OOrderNoId_P
1
77895
3
2
44678
3
3
22456
1
4
24562
1
5
34764
65
×óÁ¬½Ó£¨LEFT JOIN£©ÊµÀý
ÏÖÔÚ£¬ÎÒÃÇÏ£ÍûÁгöËùÓеÄÈË£¬ÒÔ¼°ËûÃǵĶ¨¹º - Èç¹ûÓеĻ°¡£
Äú¿ÉÒÔʹÓÃÏÂÃæµÄ SELECT Óï¾ä£º
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
from Persons
LEFT JOIN Orders
ON Persons.Id_P=Orders.Id_P
ORDER BY Persons.LastName
½á¹û¼¯£º
LastNameFirstNameOrderNo
Adams
John
22456
Adams
John
24562
Carter
Thomas
77895
Carter
Thomas
44678
Bush
George
LEFT JOIN ¹Ø¼ü×Ö»á´Ó×ó±í (Persons) ÄÇÀï·µ»ØËùÓеÄÐУ¬¼´Ê¹ÔÚÓÒ±í (Orders) ÖÐûÓÐÆ¥ÅäµÄÐС£
Ïà¹ØÎĵµ£º
µ¼³ö£º
Ö±½Ó´ò¿ª²éѯ·ÖÎöÆ÷²éѯҪµ¼³ö±íµÄÐÅÏ¢£¨select * from ±í£©£¬µÃµ½µÄ½á¹ûÈ«Ñ¡£¬ÓÒ¼üÁí´æΪ xxx.csvÎļþ £¨µÃµ½¸Ã±íµÄËùÓÐÐÅÏ¢£¬CSVÎļþ¸ñʽ£©
µ¼È룺
Ê×ÏÈͨ¹ýsql server µÄÆóÒµ¹ÜÀíÆ÷Éú³ÉÒªµ¼³ö±íµÄ SQL½Å±¾£¬²½Ö裺Ҫµ¼³ö±í——ËùÓÐÈÎÎñ£¨ÓÒ¼ü£©——Éú³ÉSQL½Å±¾
µÃµ½¸Ã±íµÄ ......
UNION½«Á½¸ö»òÁ½¸öÒÔÉϵIJéѯ½á¹ûºÏ²¢ÎªÒ»¸ö½á¹û¼¯£¬ËüÓëʹÓÃÁ¬½Ó²éѯºÏ²¢Á½¸ö±íµÄÁÐÊDz»Í¬µÄ£¬Ê¹
ÓÃUNIONºÏ²¢²éѯ±ØÐë×ñÊØ£º1ÁеÄÊýÄ¿ºÍ˳Ðò±ØÐëÒ»Ö£»2Êý¾ÝµÄÀàÐͱØÐë¼æÈÝ¡£
select Óï¾ä
UNION [all]
select Óï¾ä
¿ÉÒÔ¿´µ½£¬Ö»Òª¶ÔÓ¦×ֶεÄÀàÐÍÏàͬ¾Í¿ÉÒÔÍê³ÉºÏ²¢²Ù×÷£¬µ«ÊÇΪÁËÓÐÒâÒ壬Á½¸ö²éѯµÄ½á¹ûÓ¦¸ÃΪÏàͬ
µ ......
ÒòΪ²»Ö§³Ö´æ´¢¹ý³Ì£¬ËùÒÔ²éѯÓï¾äÈçÏ£º
string SLQuery =
"INSERT INTO ParkLocation(ParkName,Latitude, Longtitude,Charge,TotalSpace,EmptySpace,ParkCaption,UpdataTime)"+
&nb ......
´íÎó1069ÊÇÒ»¸öWindows NT/2000µÄϵͳ´íÎó¡£´íÎó1069±íÃ÷·þÎñ²»Äܱ»Æô¶¯£¨µ±Æô¶¯·þÎñʱ·µ»Ø“µÇ¼ʧ°Ü”´íÎ󣩡£ÀýÈ磬µ±Æô¶¯MSSQLServer·þÎñʱ£¬µÃµ½ÈçÏ´íÎóÌáʾ£º
·¢Éú´íÎó1069£ºÓÉÓڵǼʧ°Ü¶øÎÞ·¨Æô¶¯·þÎñ
´ËʱÕýÔÚMSSQLServer·þÎñÉÏÖ´Ðи÷þÎñ²Ù×÷
Èç¹û·þÎñ±»Ò»¸öûÓГµÇ¼·þÎñ”ȨÏÞµÄÕÊ» ......
SQL JOIN
SQL join ÓÃÓÚ¸ù¾ÝÁ½¸ö»ò¶à¸ö±íÖеÄÁÐÖ®¼äµÄ¹Øϵ£¬´ÓÕâЩ±íÖвéѯÊý¾Ý¡£
Join ºÍ Key
ÓÐʱΪÁ˵õ½ÍêÕûµÄ½á¹û£¬ÎÒÃÇÐèÒª´ÓÁ½¸ö»ò¸ü¶àµÄ±íÖлñÈ¡½á¹û¡£ÎÒÃǾÍÐèÒªÖ´ÐÐ join¡£
Êý¾Ý¿âÖеıí¿Éͨ¹ý¼ü½«±Ë´ËÁªÏµÆðÀ´¡£Ö÷¼ü£¨Primary Key£©ÊÇÒ»¸öÁУ¬ÔÚÕâ¸öÁÐÖеÄÿһÐеÄÖµ¶¼ÊÇΨһµÄ¡£ÔÚ±íÖУ¬Ã¿¸öÖ÷¼üµÄ ......