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

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 2005(´æ´¢¹ý³Ì)


Ò»£®¸ÅÊö
   ´æ´¢¹ý³ÌÊÇÒ»×éÔ¤ÏȱàÒëºÃµÄT--SQL´úÂ룬ǿµ÷Ò»µã£ºÕâЩ´úÂëÊÇÔ¤±àÒëºÃµÄ£¬¼´ÔÚÖ´ÐÐʱ¾Í²»ÓÃÔÚ½øÐбàÒëÁË£¬ÕâÑù»áÌá¸ß³ÌÐòµÄÔËÐÐЧÂÊ¡£ËüÀàËÆÓÚÆäËû¸ß¼¶ÓïÑÔÀïµÄ¹ý³Ì£¬¼´Íê³ÉÌض¨¹¦Äܵĺ¯Êý¡£´æ´¢¹ý³Ì·ÖÁ½ÀࣺϵͳÌṩµÄ´æ´¢¹ý³Ì£¬Óû§×Ô¼º¶¨ÒåµÄ´æ´¢¹ý³Ì£¬ÏµÍ³¶¨ÒåµÄÒÔ sp_Ϊǰ׺¡£
¶ ......

SQL·ÖÒ³¼¼Êõ

±¾ÎÄÀ´×Ô£ºhttp://niunan.javaeye.com/blog/264197
±È½ÏÍòÄܵķÖÒ³£º
select top Ã¿Ò³ÏÔʾµÄ¼Ç¼Êý * from topic where id not in  
(select top £¨µ±Ç°µÄÒ³Êý-1£©×ÿҳÏÔʾµÄ¼Ç¼Êý id from topic order by id& ......

ÊéдSQLʱҲ»ñµÃÖÇÄÜÌáʾ

дSQLµÄ±Èд.NET³ÌÐòµÄÌåÑéÉϲîÒ»µÈ£¬Ã»ÓÐÖÇÄÜÌáʾ£¬ÐèÒª¼Çס¹Ø¼ü×Ö£¬º¯Êý»òÕß²»¶ÏµØCopy±í×Ö¶ÎÃû£¬×Ô¶¨Ò庯Êý£¬´æ´¢¹ý³ÌÖ®ÀàµÄ¡£²»¹ýÔÚVS2010ÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃÖÇÄÜÌáʾÁË£¬ÈçÏÂÃ漸·ùͼËùʾ£º Ôڱ༭Æ÷ÖУ¬ ÊäÈë Shift + J £¨Ìáʾ£º VS2010 ¿ª·¢¹¤¾ßÖбêµÄÊÇ Ctrl +J ÆäʵӦ¸ÃÊÇ Shift + J £©¾Í¿ÉÒÔ×Ô¶¯´ò¿ªÕâ¸öÖÇÄÜÌá ......

SQL²éѯÓï¾ä¾«»ªÊ¹ÓüòÒª


SQL²éѯÓï¾ä¾«»ªÊ¹ÓüòÒª
¡¡¡¡¼òµ¥µÄTransact-SQL²éѯֻ°üÀ¨Ñ¡ÔñÁÐ±í¡¢from×Ó¾äºÍWHERE×Ӿ䡣ËüÃÇ·Ö±ð˵Ã÷Ëù²éѯÁС¢²éѯµÄ±í»òÊÓͼ¡¢ÒÔ¼°ËÑË÷Ìõ¼þµÈ¡£
¡¡¡¡ÀýÈ磬ÏÂÃæµÄÓï¾ä²éѯtesttable±íÖÐÐÕÃûΪ“ÕÅÈý”µÄnickname×ֶκÍemail×ֶΡ£
¡¡¡¡SELECT nickname,email
¡¡¡¡[1] from testtable
¡¡¡¡WHERE nam ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ