sqlµÄ INNER JOIN, left join,right joinÓï·¨
inner join(µÈÖµÁ¬½Ó) Ö»·µ»ØÁ½¸ö±íÖÐÁª½á×Ö¶ÎÏàµÈµÄÐÐ
left join(×óÁª½Ó) ·µ»Ø°üÀ¨×ó±íÖеÄËùÓмǼºÍÓÒ±íÖÐÁª½á×Ö¶ÎÏàµÈµÄ¼Ç¼
right join(ÓÒÁª½Ó) ·µ»Ø°üÀ¨ÓÒ±íÖеÄËùÓмǼºÍ×ó±íÖÐÁª½á×Ö¶ÎÏàµÈµÄ¼Ç¼
INNER JOIN Óï·¨£º
INNER JOIN Á¬½ÓÁ½¸öÊý¾Ý±íµÄÓ÷¨£º
SELECT * from ±í1 INNER JOIN ±í2 ON ±í1.×ֶκÅ=±í2.×ֶκÅ
INNER JOIN Á¬½ÓÈý¸öÊý¾Ý±íµÄÓ÷¨£º
SELECT * from (±í1 INNER JOIN ±í2 ON ±í1.×ֶκÅ=±í2.×ֶκÅ) INNER JOIN ±í3 ON ±í1.×ֶκÅ=±í3.×ֶκÅ
INNER JOIN Á¬½ÓËĸöÊý¾Ý±íµÄÓ÷¨£º
SELECT * from ((±í1 INNER JOIN ±í2 ON ±í1.×ֶκÅ=±í2.×ֶκÅ) INNER JOIN ±í3 ON ±í1.×ֶκÅ=±í3.×ֶκÅ) INNER JOIN ±í4 ON Member.×ֶκÅ=±í4.×ֶκÅ
INNER JOIN Á¬½ÓÎå¸öÊý¾Ý±íµÄÓ÷¨£º
SELECT * from (((±í1 INNER JOIN ±í2 ON ±í1.×ֶκÅ=±í2.×ֶκÅ) INNER JOIN ±í3 ON ±í1.×ֶκÅ=±í3.×ֶκÅ) INNER JOIN ±í4 ON Member.×ֶκÅ=±í4.×ֶκÅ) INNER JOIN ±í5 ON Member.×ֶκÅ=±í5.×ֶκÅ
Á¬½ÓÁù¸öÊý¾Ý±íµÄÓ÷¨£ºÂÔ£¬ÓëÉÏÊöÁª½Ó·½·¨ÀàËÆ£¬´ó¼Ò¾ÙÒ»·´Èý°É£º£©
×¢ÒâÊÂÏ
ÔÚÊäÈë×Öĸ¹ý³ÌÖУ¬Ò»¶¨ÒªÓÃÓ¢ÎÄ°ë½Ç±êµã·ûºÅ£¬µ¥´ÊÖ®¼äÁôÒ»°ë½Ç¿Õ¸ñ£»
ÔÚ½¨Á¢Êý¾Ý±íʱ£¬Èç¹ûÒ»¸ö±íÓë¶à¸ö±íÁª½Ó£¬ÄÇôÕâÒ»¸ö±íÖеÄ×ֶαØÐëÊÇ“Êý×Ö”Êý¾ÝÀàÐÍ£¬¶ø¶à¸ö±íÖеÄÏàͬ×ֶαØÐëÊÇÖ÷¼ü£¬¶øÇÒÊÇ“×Ô¶¯±àºÅ”Êý¾ÝÀàÐÍ¡£·ñÔò£¬ºÜÄÑÁª½Ó³É¹¦¡£
´úÂëǶÌ׿ìËÙ·½·¨£ºÈ磬ÏëÁ¬½ÓÎå¸ö±í£¬ÔòÖ»ÒªÔÚÁ¬½ÓËĸö±íµÄ´úÂëÉϼÓÒ»¸öÇ°ºóÀ¨ºÅ£¨Ç°À¨ºÅ¼ÓÔÚfromµÄºóÃ棬ºóÀ¨ºÅ¼ÓÔÚ´úÂëµÄĩβ¼´¿É£©£¬È»ºóÔÚºóÀ¨ºÅºóÃæ¼ÌÐøÌí¼Ó“INNER JOIN ±íÃûX ON ±í1.×ֶκÅ=±íX.×ֶκŔ´úÂë¼´¿É£¬ÕâÑù¾Í¿ÉÒÔÎÞÏÞÁª½ÓÊý¾Ý±íÁË£º£©
inner join on, left join on, right join on½²½â(תÔØ)
1.ÀíÂÛ
Ö»ÒªÁ½¸ö±íµÄ¹«¹²×Ö¶ÎÓÐÆ¥ÅäÖµ£¬¾Í½«ÕâÁ½¸ö±íÖеļǼ×éºÏÆðÀ´¡£
¸öÈËÀí½â£ºÒÔÒ»¸ö¹²Í¬µÄ×Ö¶ÎÇóÁ½¸ö±íÖзûºÏÒªÇóµÄ½»¼¯£¬²¢½«Ã¿¸ö±í·ûºÏÒªÇóµÄ¼Ç¼ÒÔ¹²Í¬µÄ×Ö¶ÎΪǣÒýºÏ²¢ÆðÀ´¡£
Óï·¨
from table1 INNER JOIN table2 ON table1 . field1 compopr table2 . field2
INNER JOIN ²Ù×÷°üº¬ÒÔϲ¿·Ö£º
²¿·Ö
˵Ã÷
table1, table2
Òª×éºÏÆäÖеļǼµÄ±íµÄÃû³Æ¡£
field1£¬field2
ÒªÁª½ÓµÄ×ֶεÄÃû³Æ¡£Èç¹ûËüÃDz»ÊÇÊý×Ö£¬ÔòÕâЩ×ֶεÄÊý¾ÝÀàÐͱØÐëÏàͬ£¬²¢ÇÒ°üº¬Í¬ÀàÊý¾Ý£¬µ«ÊÇ£¬ËüÃDz»±Ø¾ßÓÐÏàͬµÄÃû³Æ¡£
compopr
ÈκιØϵ±È½ÏÔËËã·û£º&l
Ïà¹ØÎĵµ£º
SQL Server 2008ÖеıíÖµÐͲÎÊý
×÷ÕߣºAl Tenhundfeld ÒëÕß Õź£Áú¡¡
±íÖµÐͲÎÊý£¨Table-valued parameters£©ÊÇSQL Server 2008ÖÐÒýÈëµÄÒ»ÖÖÐÂÌØÐÔ£¬ËüÌṩÁËÒ»ÖÖÄÚÖõķ½Ê½£¬Èÿͻ§¶ËÓ¦ÓÿÉÒÔֻͨ¹ýµ¥¶ÀµÄÒ»Ìõ²Î»¯ÊýSQLÓï¾ä£¬¾Í¿ÉÒÔÏòSQL Server·¢ËͶàÐÐÊý¾Ý¡£
±íÖ ......
¸ÅÊö
Microsoft SQL Server 2008 ÈÃÄúÄܹ»Í¨¹ýÖ±¹ÛµÄÊý¾ÝÍÚ¾òµÄÔ¤²âÐÔ·ÖÎöÀ´×ö³öÃ÷ÖǺÏÀíµÄ¾ö²ß£¬ÎÞ·ìµØÕûºÏ Microsoft ÉÌÒµÖÇÄÜƽ̨²¢¿ÉÀ©Õ¹ÖÁÉÌÒµÓ¦ÓóÌÐò¡£
ÖØ´óµÄй¦ÄÜ
ͬʱÀûÓôíÎóºÍ¾«È·¶ÈµÄͳ¼Æ·ÖÊýÀ´²âÊÔ¶à¸öÊý¾ÝÍÚ¾òÄ£ÐÍ£¬²¢ÀûÓý»²æÑéÖ¤À´È·ÈÏÆäÎȶ¨ÐÔ
ÔÚµ¥Ò»½á¹¹Öн¨Á¢¶à¸ö²»¼æÈݵÄÍÚ¾òÄ£ÐÍ¡¢ÔÚɸѡ¹ýµÄÊ ......
±¾ÎÄÀ´×Ô£ºhttp://www.cnblogs.com/digjim/archive/2006/09/20/509344.html
ÎÒÃÇÖªµÀ£¬SQL Server 2005ºÍSQL Server 2000 Ïà±È½Ï£¬SQL Server 2005ÓкܶàÐÂÌØÐÔ¡£ÕâƪÎÄÕÂÎÒÃÇÒªÌÖÂÛÆäÖеÄÒ»¸öк¯ÊýRow_Number()¡£Êý¾Ý¿â¹ÜÀíÔ±ºÍ¿ª·¢ÕßÒѾÆÚ´ýÕâ¸öº¯ÊýºÜ¾ÃÁË£¬ÏÖÔÚÖÕÓڵȵ½ÁË£¡
ͨ³££¬¿ª·¢Õߺ͹ÜÀíÔ±ÔÚÒ»¸ö ......
select pcode from (
select h.k,h.d,h.m,h.u,l.areacode,
l.areacode||substr(h.u,4,length(h.u))||h.k pcode
from(
&nb ......
дSQLµÄ±Èд.NET³ÌÐòµÄÌåÑéÉϲîÒ»µÈ£¬Ã»ÓÐÖÇÄÜÌáʾ£¬ÐèÒª¼Çס¹Ø¼ü×Ö£¬º¯Êý»òÕß²»¶ÏµØCopy±í×Ö¶ÎÃû£¬×Ô¶¨Ò庯Êý£¬´æ´¢¹ý³ÌÖ®ÀàµÄ¡£²»¹ýÔÚVS2010ÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃÖÇÄÜÌáʾÁË£¬ÈçÏÂÃ漸·ùͼËùʾ£º ÔÚ±à¼Æ÷ÖУ¬ ÊäÈë Shift + J £¨Ìáʾ£º VS2010 ¿ª·¢¹¤¾ßÖбêµÄÊÇ Ctrl +J ÆäʵӦ¸ÃÊÇ Shift + J £©¾Í¿ÉÒÔ×Ô¶¯´ò¿ªÕâ¸öÖÇÄÜÌá ......