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

SQL RIGHT JOIN ¹Ø¼ü×Ö

SQL RIGHT JOIN ¹Ø¼ü×Ö
SQL RIGHT JOIN ¹Ø¼ü×Ö
RIGHT JOIN ¹Ø¼ü×Ö»áÓÒ±í (table_name2) ÄÇÀï·µ»ØËùÓеÄÐУ¬¼´Ê¹ÔÚ×ó±í (table_name1) ÖÐûÓÐÆ¥ÅäµÄÐС£
RIGHT JOIN ¹Ø¼ü×ÖÓï·¨
SELECT column_name(s)
from table_name1
RIGHT JOIN table_name2
ON table_name1.column_name=table_name2.column_name
×¢ÊÍ£ºÔÚijЩÊý¾Ý¿âÖУ¬ RIGHT JOIN ³ÆΪ RIGHT 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
ÓÒÁ¬½Ó£¨RIGHT JOIN£©ÊµÀý
ÏÖÔÚ£¬ÎÒÃÇÏ£ÍûÁгöËùÓеĶ¨µ¥£¬ÒÔ¼°¶¨¹ºËüÃǵÄÈË - Èç¹ûÓеĻ°¡£
Äú¿ÉÒÔʹÓÃÏÂÃæµÄ SELECT Óï¾ä£º
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
from Persons
RIGHT 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
 
 
34764
RIGHT JOIN ¹Ø¼ü×Ö»á´ÓÓÒ±í (Orders) ÄÇÀï·µ»ØËùÓеÄÐУ¬¼´Ê¹ÔÚ×ó±í (Persons) ÖÐûÓÐÆ¥ÅäµÄÐС£


Ïà¹ØÎĵµ£º

º½¿Õ¹«Ë¾¹ÜÀíϵͳ(VC++ ÓëSQL 2005)

ϵͳ»·¾³£ºWindows 7
Èí¼þ»·¾³£ºVisual C++ 2008 SP1 +SQL Server 2005
±¾´ÎÄ¿µÄ£º±àдһ¸öº½¿Õ¹ÜÀíϵͳ
      ÕâÊÇÊý¾Ý¿â¿Î³ÌÉè¼ÆµÄ³É¹û£¬ËäÈ»³É¼¨²»¼Ñ£¬µ«ÊÇ×÷ΪÎÒÓÃVC++ ÒÔÀ´±àдµÄ×î´ó³ÌÐò»¹ÊÇ´«µ½ÍøÉÏ£¬ÒÔ¹©²Î¿¼¡£ÓÃVC++ ×öÊý¾Ý¿âÉè¼Æ²¢²»ÈÝÒ×£¬µ«Ò²²»ÊDz»¿ÉÄÜ¡£ÒÔÏÂÊÇÎҵijÌÐò½çÃ棬ºóÃæ ......

SQLÓïÑÔ»ù´¡£¨1£©

¶ÔÏóÃüÃûµÄÔ¼¶¨£ºÊý¾Ý¿âÃû.ËùÓÐÕßÃû.¶ÔÏóÃû
Ç°Á½Õß¿ÉÊ¡ÂÔ£¬Ä¬ÈÏÖµÊý¾Ý¿âÊǵ±Ç°Êý¾Ý¿â£¬ËùÓÐÕßÊÇdbo
±ðÃû£ºÊý¾Ý¿âÃû³Æ as Êý¾Ý¿â±íÃû Ö÷ÒªÊÇÔö¼ÓselectÓï¾äµÄ¿É¶ÁÐÔ£¬Èç¹ûÒѾ­ÎªÊý¾Ý±íÖƶ¨Á˱ðÃû£¬Ôò
ÔÚÏàÓ¦µÄSQLÓï¾äÖУ¬¶Ô¸ÃÊý¾Ý±íµÄËùÓÐÏÔʾÒýÓö¼ÒªÊ¹ÓñðÃû£¬¶ø²»ÄÜʹÓÃÊý¾Ý±íÃû¡£
selectÓï¾äÊÇÊý¾Ý¼ìË÷ÖÐ×îƵ·±µÄ»î¶ ......

SQLÓïÑÔ»ù´¡£¨4£©

UNION½«Á½¸ö»òÁ½¸öÒÔÉϵIJéѯ½á¹ûºÏ²¢ÎªÒ»¸ö½á¹û¼¯£¬ËüÓëʹÓÃÁ¬½Ó²éѯºÏ²¢Á½¸ö±íµÄÁÐÊDz»Í¬µÄ£¬Ê¹
ÓÃUNIONºÏ²¢²éѯ±ØÐë×ñÊØ£º1ÁеÄÊýÄ¿ºÍ˳Ðò±ØÐëÒ»Ö£»2Êý¾ÝµÄÀàÐͱØÐë¼æÈÝ¡£
select Óï¾ä
UNION [all]
select Óï¾ä
¿ÉÒÔ¿´µ½£¬Ö»Òª¶ÔÓ¦×ֶεÄÀàÐÍÏàͬ¾Í¿ÉÒÔÍê³ÉºÏ²¢²Ù×÷£¬µ«ÊÇΪÁËÓÐÒâÒ壬Á½¸ö²éѯµÄ½á¹ûÓ¦¸ÃΪÏàͬ
µ ......

SQL SERVER CEÖÐ ²éѯÓï¾ä±äÁ¿µÄʹÓÃ

ÒòΪ²»Ö§³Ö´æ´¢¹ý³Ì£¬ËùÒÔ²éѯÓï¾äÈçÏ£º
string SLQuery =
                "INSERT INTO ParkLocation(ParkName,Latitude, Longtitude,Charge,TotalSpace,EmptySpace,ParkCaption,UpdataTime)"+
      &nb ......

SQL UnionºÍSQL Union AllÓ÷¨

UNION Ö¸ÁîµÄÄ¿µÄÊǽ«Á½¸ö SQL Óï¾äµÄ½á¹ûºÏ²¢ÆðÀ´¡£´ÓÕâ¸ö½Ç¶ÈÀ´¿´£¬ UNION ¸ú JOIN ÓÐЩÐíÀàËÆ£¬ÒòΪÕâÁ½¸öÖ¸Á¿ÉÒÔÓɶà¸ö±í¸ñÖÐߢȡ×ÊÁÏ¡£ UNION µÄÒ»¸öÏÞÖÆÊÇÁ½¸ö SQL Óï¾äËù²úÉúµÄÀ¸Î»ÐèÒªÊÇͬÑùµÄ×ÊÁÏÖÖÀà¡£ÁíÍ⣬µ±ÎÒÃÇÓà UNIONÕâ¸öÖ¸Áîʱ£¬ÎÒÃÇÖ»»á¿´µ½²»Í¬µÄ×ÊÁÏÖµ (ÀàËÆ SELECT DISTINCT)¡£ unionÖ»Êǽ«Á½¸ö½á¹ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ