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

SQL UNION ºÍUNION ALL ²Ù×÷·û


SQL UNION ²Ù×÷·û
UNION ²Ù×÷·ûÓÃÓںϲ¢Á½¸ö»ò¶à¸ö SELECT Óï¾äµÄ½á¹û¼¯¡£
Çë×¢Ò⣬UNION ÄÚ²¿µÄ SELECT Óï¾ä±ØÐëÓµÓÐÏàͬÊýÁ¿µÄÁС£ÁÐÒ²±ØÐëÓµÓÐÏàËƵÄÊý¾ÝÀàÐÍ¡£Í¬Ê±£¬Ã¿Ìõ SELECT Óï¾äÖеÄÁеÄ˳Ðò±ØÐëÏàͬ¡£
SQL UNION Óï·¨
SELECT column_name(s) from table_name1
UNION
SELECT column_name(s) from table_name2
×¢ÊÍ£ºÄ¬Èϵأ¬UNION ²Ù×÷·ûÑ¡È¡²»Í¬µÄÖµ¡£Èç¹ûÔÊÐíÖظ´µÄÖµ£¬ÇëʹÓà UNION ALL¡£
SQL UNION ALL Óï·¨
SELECT column_name(s) from table_name1
UNION ALL
SELECT column_name(s) from table_name2
ÁíÍ⣬UNION ½á¹û¼¯ÖеÄÁÐÃû×ÜÊǵÈÓÚ UNION ÖеÚÒ»¸ö SELECT Óï¾äÖеÄÁÐÃû¡£
ÏÂÃæµÄÀý×ÓÖÐʹÓõÄԭʼ±í£º
Employees_China:
E_IDE_Name
01
Zhang, Hua
02
Wang, Wei
03
Carter, Thomas
04
Yang, Ming
Employees_USA:
E_IDE_Name
01
Adams, John
02
Bush, George
03
Carter, Thomas
04
Gates, Bill
ʹÓà UNION ÃüÁî
ʵÀý
ÁгöËùÓÐÔÚÖйúºÍÃÀ¹úµÄ²»Í¬µÄ¹ÍÔ±Ãû£º
SELECT E_Name from Employees_China
UNION
SELECT E_Name from Employees_USA
½á¹û
E_Name
Zhang, Hua
Wang, Wei
Carter, Thomas
Yang, Ming
Adams, John
Bush, George
Gates, Bill
×¢ÊÍ£ºÕâ¸öÃüÁîÎÞ·¨ÁгöÔÚÖйúºÍÃÀ¹úµÄËùÓйÍÔ±¡£ÔÚÉÏÃæµÄÀý×ÓÖУ¬ÎÒÃÇÓÐÁ½¸öÃû×ÖÏàͬµÄ¹ÍÔ±£¬ËûÃǵ±ÖÐÖ»ÓÐÒ»¸öÈ˱»ÁгöÀ´ÁË¡£UNION ÃüÁîÖ»»áÑ¡È¡²»Í¬µÄÖµ¡£
UNION ALL
UNION ALL ÃüÁîºÍ UNION ÃüÁºõÊǵÈЧµÄ£¬²»¹ý UNION ALL ÃüÁî»áÁгöËùÓеÄÖµ¡£
SQL Statement 1
UNION ALL
SQL Statement 2
ʹÓà UNION ALL ÃüÁî
ʵÀý£º
ÁгöÔÚÖйúºÍÃÀ¹úµÄËùÓеĹÍÔ±£º
SELECT E_Name from Employees_China
UNION ALL
SELECT E_Name from Employees_USA
½á¹û
E_Name
Zhang, Hua
Wang, Wei
Carter, Thomas
Yang, Ming
Adams, John
Bush, George
Carter, Thomas
Gates, Bill
Ô­ÌûµØÖ·£ºhttp://www.w3school.com.cn/sql/sql_union.asp


Ïà¹ØÎĵµ£º

SQL ServerÖеÄÃüÃû¹ÜµÀ(named pipe)¼°ÆäʹÓÃ

1. ʲôÊÇÃüÃû¹ÜµÀ£¿
ÓëTCP/IP£¨´«Êä¿ØÖÆЭÒé»òinternetЭÒ飩һÑù£¬ÃüÃû¹ÜµÀÊÇÒ»ÖÖͨѶЭÒé¡£ËüÒ»°ãÓÃÓÚ¾ÖÓòÍøÖУ¬ÒòΪËüÒªÇó¿Í»§¶Ë±ØÐë¾ßÓзÃÎÊ·þÎñÆ÷×ÊÔ´µÄȨÏÞ¡£
Òª½âÊÍÕâ¸öÎÊÌ⣬ÎÒ»¹ÊÇժ¼΢Èí¹Ù·½µÄ×ÊÁϱȽϺÃ
http://msdn.microsoft.com/zh-cn/library/ms187892.aspx
ÈôÒªÁ¬½Óµ½ SQL Server Êý¾Ý¿âÒýÇ棬±ØÐëÆô ......

oracle pl/sqlʵÀýÁ·Ï°


µÚÒ»²¿·Ö£ºoracle pl/sqlʵÀýÁ·Ï°(1)
Ò»¡¢Ê¹ÓÃscott/tigerÓû§ÏµÄemp±íºÍdept±íÍê³ÉÏÂÁÐÁ·Ï°£¬±íµÄ½á¹¹ËµÃ÷ÈçÏÂ
empÔ±¹¤±í(empnoÔ±¹¤ºÅ/enameÔ±¹¤ÐÕÃû/job¹¤×÷/mgrÉϼ¶±àºÅ/hiredateÊܹÍÈÕÆÚ/salн½ð/commÓ¶½ð/deptno²¿ÃűàºÅ)
dept²¿Ãűí(deptno²¿ÃűàºÅ/dname²¿ÃÅÃû³Æ/locµØµã)
¹¤×Ê £½ н½ð £« Ó¶½ð
Ò²¿ÉÒÔͨ¹ý ......

SQL ×Ö¶Î帶¿Õ

SELECT * from xcmis.temp_odr_prom@linkxceis where trim(ODR_NO) like 'CA10010082'
SELECT * from xcmis.temp_odr_prom@linkxceis where ODR_NO like 'CA10010082%'
SELECT * from xcmis.temp_odr_prom@linkxceis where ODR_NO = 'CA10010082'
OK
SELECT * from xcmis.temp_odr_prom@linkxceis where ODR_NO like 'C ......

oracle sql*plus set &spool½éÉÜ(¶þ)

Oracle spool Ó÷¨Ð¡½á[°ëת°ë¼Ó]
¹ØÓÚSPOOL(SPOOLÊÇSQLPLUSµÄÃüÁ²»ÊÇSQLÓï·¨ÀïÃæµÄ¶«Î÷¡£)
¶ÔÓÚSPOOLÊý¾ÝµÄSQL£¬×îºÃÒª×Ô¼º¶¨Òå¸ñʽ£¬ÒÔ·½±ã³ÌÐòÖ±½Óµ¼Èë,SQLÓï¾äÈ磺
select empno||','||ename||','||sal from emp;
spool³£ÓõÄÉèÖÃ
set colsep' ';¡¡¡¡¡¡ //ÓòÊä³ö·Ö¸ô·û
set echo off;¡¡¡¡¡¡¡¡//ÏÔʾstartÆô¶¯µ ......

50¸ö³£ÓõÄSQLÓï¾ä

Student(S#,Sname,Sage,Ssex) ѧÉú±í 
Course(C#,Cname,T#) ¿Î³Ì±í 
SC(S#,C#,score) ³É¼¨±í 
Teacher(T#,Tname) ½Ìʦ±í 
ÎÊÌ⣺ 
1¡¢²éѯ“001”¿Î³Ì±È“002”¿Î³Ì³É¼¨¸ßµÄËùÓÐѧÉúµÄѧºÅ£» 
select a.S# from (select s#,score from SC where C#='001') a,(sele ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ