Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

sqlÁ¬½Ó£¨ÄÚÁ¬½Ó¡¢ÍâÁ¬½Ó¡¢È«Á¬½Ó£©

ÏÖÓÐtable_for_report_1ºÍtable_for_report_2£¬ÏêÇéÈçÏ£º
table_for_report_1ÓÐnum×ֶΣ¬c1,c2,c3×ֶΡ£
Êý¾ÝÈçÏ£º
    num                c1  c2  c3
1 15001346690 11 12 13
2 13329921100 21 22 23
3 18900000000 31 32 33
4 13811111111 41 42 43
table_for_report_2ÓÐnum×ֶΣ¬c4,c5×ֶΡ£
Êý¾ÝÈçÏ£º
    num                c4  c5 
1 13822222222 34 35
2 15001346690 14 15
3 13811111111 24 25
 
ÄÚÁ¬½Ó£º
select t1.num,t1.c1,t1.c2,t1.c3,t2.c4,t2.c5
from table_for_report_1 t1, table_for_report_2 t2
where t1.num=t2.num
½á¹û£º
    num                c1  c2 c3 c4 c5
1 15001346690 11 12 13 14 15
2 13811111111 41 42 43 24 25
ÍâÁ¬½Ó£¨×óÍâÁ¬½ÓºÍÓÒÍâÁ¬½Ó£©£º
1£©×óÍâÁ¬½Ó£º
select t1.num,t1.c1,t1.c2,t1.c3,t2.c4,t2.c5
from table_for_report_1 t1, table_for_report_2 t2
where t1.num=t2.num(+)
»òÕß
select t1.num,t1.c1,t1.c2,t1.c3,t2.c4,t2.c5
from table_for_report_1 t1 left outer join table_for_report_2 t2
on (t1.num=t2.num)
½á¹û£º
    num                c1  c2 c3 c4 c5
1 15001346690 11 12 13 14 15
2 13811111111 41 42 43 24 25
3 18900000000 31 32 33  
4 13329921100 21 22 23  
2£©ÓÒÍâÁ¬½Ó£º
select t2.num,t1.c1,t1.c2,t1.c3,t2.c4,t2.c5
from table_for_report_1 t1, table_for_report_2 t2
where t1.num(+)=t2.num
»òÕß
select t2.num,t1.c1,t1.c2,t1.c3,t2.c4,t2.c5
from table_for_rep


Ïà¹ØÎĵµ£º

SQL JOIN

SQL JOIN
 
SQL join ÓÃÓÚ¸ù¾ÝÁ½¸ö»ò¶à¸ö±íÖеÄÁÐÖ®¼äµÄ¹ØÏµ£¬´ÓÕâЩ±íÖвéѯÊý¾Ý¡£
Join ºÍ Key
ÓÐʱΪÁ˵õ½ÍêÕûµÄ½á¹û£¬ÎÒÃÇÐèÒª´ÓÁ½¸ö»ò¸ü¶àµÄ±íÖлñÈ¡½á¹û¡£ÎÒÃǾÍÐèÒªÖ´ÐÐ join¡£
Êý¾Ý¿âÖеıí¿Éͨ¹ý¼ü½«±Ë´ËÁªÏµÆðÀ´¡£Ö÷¼ü£¨Primary Key£©ÊÇÒ»¸öÁУ¬ÔÚÕâ¸öÁÐÖеÄÿһÐеÄÖµ¶¼ÊÇΨһµÄ¡£ÔÚ±íÖУ¬Ã¿¸öÖ÷¼üµÄ ......

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
×¢ÊÍ£ºÔÚÄ ......

Àμǣ¡SQL ServerÊý¾Ý¿â¿ª·¢µÄ¶þʮһÌõ¾ü¹æ(SQLÊÕ²Ø)

Èç¹ûÄãÕýÔÚ¸ºÔðÒ»¸ö»ùÓÚSQL ServerµÄÏîÄ¿£¬»òÕßÄã¸Õ¸Õ½Ó´¥SQL Server£¬Äã¶¼ÓпÉÄÜÒªÃæÁÙһЩÊý¾Ý¿âÐÔÄܵÄÎÊÌ⣬ÕâÆªÎÄÕ»áΪÄãÌṩһЩÓÐÓõÄÖ¸µ¼£¨ÆäÖдó¶àÊýÒ²¿ÉÒÔÓÃÓÚÆäËüµÄDBMS£©¡£
ÔÚÕâÀÎÒ²»´òËã½éÉÜʹÓÃSQL ServerµÄÇÏÃÅ£¬Ò²²»ÄÜÌṩһ¸ö°üÖΰٲ¡µÄ·½°¸£¬ÎÒËù×öµÄÊÇ×ܽáһЩ¾­Ñé----¹ØÓÚÈçºÎÐγÉÒ»¸öºÃµÄÉè¼Æ¡£Õ ......

ÎåÖÖÌá¸ß SQL ÐÔÄܵķ½·¨

ÎåÖÖÌá¸ß SQL ÐÔÄܵķ½·¨
ÓÐʱ£¬ ΪÁËÈÃÓ¦ÓóÌÐòÔËÐеøü¿ì£¬Ëù×öµÄÈ«²¿¹¤×÷¾ÍÊÇÔÚÕâÀï»òÄÇÀï×öһЩºÜСµ÷Õû¡£°¡£¬µ«¹Ø¼üÔÚÓÚÈ·¶¨ÈçºÎ½øÐе÷Õû£¡³ÙÔçÄú»áÓöµ½ÕâÖÖÇé¿ö£ºÓ¦ÓóÌÐòÖÐµÄ SQL ²éѯ²»Äܰ´ÕÕÄúÏëÒªµÄ·½Ê½½øÐÐÏìÓ¦¡£ËüҪô²»·µ»ØÊý¾Ý£¬ÒªÃ´ºÄ·ÑµÄʱ¼ä³¤µÃ³öÆæ¡£Èç¹ûËü½µµÍÁ˱¨¸æ»òÄúµÄÆóÒµÓ¦ÓóÌÐòµÄËÙ¶È£¬Óû§±ØÐ ......

SQL Server: Inner Join¼°Outer Join, Natrual Jion

Ò»¡¢NATURAL JOIN£¨×ÔÈ»Á¬½Ó£©
     Á½Õűíͨ¹ýNATURAL JOINÁ¬½ÓµÄʱºò£¬Ï൱ÓÚÓиöÒþº¬µÄWHERE×Ӿ䣬¶ÔÁ½ÕűíÖÐͬÃûµÄ¶ÔÓ¦ÁÐÏà±È½Ï¿´ÊÇ·ñÏàµÈ¡£
¶þ¡¢CROSS JOIN£¨´´½¨µÑ¿¨¶û»ý£©
     ¶ÔÁ½Õűíͨ¹ý½»²æÁªºÏ²úÉúµÚÈýÕÅ·µ»Ø½á¹û¼¯µÄ±í¡£Ï൱ÓÚÆÕͨµÄÁ¬½Ó¡£
Èý¡¢INNER JOIN£ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ