sql unionÓ÷¨ºÍsql union allÓ÷¨,sql unionЧÂÊ
sql unionÓ÷¨ºÍsql union allÓ÷¨,sql unionЧÂÊ
1¡¢sql unionÓ÷¨
sql unionÔÚ²éѯÖпÉÒÔ½«Á½¸öSQL Óï¾äµÄ½á¹ûºÏ²¢ÆðÀ´¡£Èç¹ûÕâÑù¿´µÄ»°£¬ UNION ¸ú JOIN ÊÇÏàËƵģ¬Á½¸öÖ¸Á¿ÉÒÔÓɶà¸ö±í¸ñÖÐߢȡ×ÊÁÏ¡£
sql unionµÄÒ»¸öÏÞÖÆÊÇÁ½¸ö SQL Óï¾äËù²úÉúµÄÀ¸Î»ÐèÒªÊÇͬÑùµÄ×ÊÁÏÖÖÀà¡£ÁíÍ⣬µ±ÎÒÃÇÓà UNIONÕâ¸öÖ¸Áîʱ£¬ÎÒÃÇÖ»»á¿´µ½²»Í¬µÄ×ÊÁÏÖµ (ÀàËÆ SELECT DISTINCT)¡£
sql unionÖ»Êǽ«Á½¸ö½á¹ûÁª½áÆðÀ´Ò»ÆðÏÔʾ£¬²¢²»ÊÇÁª½áÁ½¸ö±í£¬sqlÓ÷¨ÈçÏ£º
Á½¸ö±í¸ñ£¬ StoreData_200903 ±í¸ñ StoreData_200904£¬ÕâÁ½Õűí¸ñµÄÊý¾Ý½á¹¹ÊÇÍêÈ«Ò»ÑùµÄ£¬Ö»ÊÇ´æ·ÅÁ˲»Í¬Ô·ݵÄÊý¾Ý¿â£¨×¢Ò⣺ÕâÑù×öÊÇΪÁËÄܹ»·Ö±í£¬¶øÇÒ¿ÉÒÔ°´Ô´浵Êý¾Ý£©£¬ÏÖÔÚÐèÒªÁªºÏ²éѯ£¬¾ÍÊÇ´ÓÁ½¸ö±íÖвéѯ³öÊý¾Ý£¬SQL Óï¾ä£º
SELECT top 50 from StoreData_200903
UNION
SELECT top 50 from StoreData_200904
2¡¢sql union allÓ÷¨
sql union allÕâ¸öÖ¸ÁîµÄÄ¿µÄÒ²ÊÇÒª½«Á½¸ö SQL Óï¾äµÄ½á¹ûºÏ²¢ÔÚÒ»Æð¡£ sql union allºÍ sql union²»Í¬Ö®´¦ÔÚÓÚ sql union all»á½«Ã¿Ò»´Î·ûºÏÌõ¼þµÄÊý¾ÝÁгöÀ´£¬ÎÞÂÛÊý¾Ý¿âÓÐÎÞÖظ´¡£
Ó÷¨Ò²ºÜ¼òµ¥£º
SELECT top 50 from StoreData_200903
UNION ALL
SELECT top 50 from StoreData_200904
ÖµµÃ×¢ÒâµÄÊÇ£¬sql union allµÄÖ´ÐÐЧÂÊÒª±Èsql unionЧÂÊÒª¸ßºÜ¶à£¬ÕâÊÇÒòΪ£¬Ê¹ÓÃsql unionÐèÒª½øÐÐÅÅÖØ£¬¶øsql union All ÊDz»ÐèÒªÅÅÖصģ¬ÕâÒ»µã·Ç³£ÖØÒª£¬ÒòΪ¶ÔÓÚһЩµ¥´¿µØʹÓ÷ֱíÀ´Ìá¸ßЧÂʵIJéѯ£¬ÍêÈ«¿ÉÒÔʹÓÃsql union All¡£
»¹ÓУ¬Èç¹ûʹÓÃÁËunion£¬ÎÞÂÛÊÇsql union»¹ÊÇsql union allÒ»¶¨Òª¼Çס¶ÔÊý¾Ý¿â±í¼ÓÉÏË÷Òý£¡
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ÔÚÊý¾Ý¿âÖУ¬unionºÍunion all ¹Ø¼ü×Ö¶¼Êǽ«Á½¸ö½á¹û¼¯ºÏºÏ²¢ÎªÒ»¸ö£¬µ«ÕâÁ½Õß´ÓʹÓúÍЧÂÊÉÏÀ´Ëµ¶¼ÓÐËù²»Í¬¡£
UNIONÔÚ½øÐбíÁ´½Óºó»áɸѡµôÖظ´µÄ¼Ç¼£¬ËùÒÔÔÚ±íÁ´½Óºó»á¶ÔËù²úÉúµÄ½á¹û¼¯½øÐÐÅÅÐòÔËË㣬ɾ³ýÖظ´µÄ¼Ç¼ÔÙ·µ»Ø½á¹û¡£Êµ¼Ê´ó²¿·ÖÓ¦ÓÃÖÐÊDz»»á²úÉúÖظ´µÄ¼Ç¼£¬×î³£¼ûµÄÊǹý³Ì±íÓëÀúÊ·±íUNION¡£È磺
select * from gc_dfys
union
select * from ls_jg_dfys
Õâ¸öSQLÔÚÔËÐÐʱÏÈÈ¡³öÁ½¸ö±íµÄ½á¹û£¬ÔÙÓÃÅÅÐò¿Õ¼ä½øÐÐÅÅÐòɾ³ýÖظ´µÄ¼Ç¼£¬×îºó·µ»Ø½á¹û¼¯£¬Èç¹û±íÊý¾ÝÁ¿´óµÄ»°¿ÉÄܻᵼÖÂÓôÅÅ̽øÐÐÅÅÐò¡£
¶øUNION ALLÖ»ÊǼòµ¥µÄ½«Á½¸ö½á¹ûºÏ²¢ºó¾Í·µ»Ø¡£ÕâÑù£¬Èç¹û·µ»
Ïà¹ØÎĵµ£º
СµÜÏëÎʸöÎÊÌ⣬ÔÚSQL Server 2005ÉÏ£¬½¨Á¢Ö÷¼üµÄͬʱ¾Í»áĬÈÏÔÚÖ÷¼üÉÏÉèÖþ۴ØË÷Òý£¬ÄÇôÄÜ·ñÔÚÒ»¸ö×Ö¶ÎÉÏÉèÖÃÖ÷¼üºÍΨһÐÔË÷Òý£¨Unique£©£¬µ«ÊǰѾ۴ØË÷ÒýÉèÖõ½ÁíÒ»¸ö×Ö¶ÎÉÏ£¿
¾Ù¸ö¼òµ¥µÄÀý×Ó£¬±ÈÈçÎÒÓиö±í½ÐTableTest£¬±íÀïÓÐÁ½¸ö×ֶΣ¬id,date£¬±¾À´idÊÇÖ÷¼üµÄ£¬ÎÒÏÖÔÚÏë°Ñ¾Û´ØË÷ÒýÉèÖõ½date×Ö¶ÎÉÏ¡£
ÎÒÏÈɾ³ýÖ ......
´æ´¢¹ý³Ì
==========================================================================
==========================================================================
¡¾ÑµÁ·15.1¡¿ ´´½¨Ò»¸öÏÔʾ¹ÍÔ±×ÜÈËÊýµÄ´æ´¢¹ý³Ì¡£
²½Öè1£ºµÇ¼SCOTTÕË»§(»òѧÉú¸öÈËÕË»§)¡£
²½Öè2£º ......
SQL Server 2008ÖеıíÖµÐͲÎÊý
×÷ÕߣºAl Tenhundfeld ÒëÕß Õź£Áú¡¡
±íÖµÐͲÎÊý£¨Table-valued parameters£©ÊÇSQL Server 2008ÖÐÒýÈëµÄÒ»ÖÖÐÂÌØÐÔ£¬ËüÌṩÁËÒ»ÖÖÄÚÖõķ½Ê½£¬Èÿͻ§¶ËÓ¦ÓÿÉÒÔֻͨ¹ýµ¥¶ÀµÄÒ»Ìõ²Î»¯ÊýSQLÓï¾ä£¬¾Í¿ÉÒÔÏòSQL Server·¢ËͶàÐÐÊý¾Ý¡£
±íÖ ......
¡¡×î½üÔÚÕÛÌÚ PHP + MYSQL
µÄ±à³Ì¡£Á˽âÁËһЩ PHP SQL ×¢Èë¹¥»÷
µÄ֪ʶ£¬ÓÚÊÇдÁËÕâƪÎÄÕ¡¡http://www.xiaohui.com/weekly/20070314.htm£¬×ܽáһϾÑé¡£ÔÚÎÒ¿´À´£¬Òý·¢ SQL ×¢Èë¹¥»÷
µÄÖ÷ÒªÔÒò£¬ÊÇÒòΪÒÔÏÂÁ½µãÔÒò£º
¡¡¡¡1. php ÅäÖÃÎļþ php.ini ÖÐµÄ magic_quotes_gpc
Ñ¡ÏîûÓдò¿ª£¬±»ÖÃΪ off
¡¡¡¡2. ¿ª·¢ ......
¸ÅÊö
Microsoft SQL Server 2008 ÌṩÁËÓÐÖúÓÚÓÐЧ¹ÜÀí°²È«ÐÔ¹¦ÄÜÅäÖá¢Ç¿Éí·ÝÑéÖ¤ºÍ·ÃÎÊ¿ØÖƵݲȫÐÔÔöÇ¿¹¦ÄÜ¡¢¹¦ÄÜÇ¿´óµÄ¼ÓÃܺÍÃÜÔ¿¹ÜÀí¹¦ÄÜ£¬ÒÔ¼°ÔöÇ¿ÐÍÉóºË¹¦ÄÜ¡£
ÖØ´óµÄй¦ÄÜ
ʹÓûùÓÚ²ßÂԵĹÜÀí£¬Õë¶ÔÆóÒµÄÚµÄÊý¾ÝÀ´¹ÜÀí¼°¼ì²â²»·ûºÏ°²È«²ßÂÔµÄÇé¿ö
²»ÐèÐÞ¸ÄÓ¦ÓóÌÐò¼´¿ÉʹÓÃ͸Ã÷Êý¾Ý¼ÓÃÜÀ´¼ÓÃÜÊý¾Ý
ʹÓÿÉÀ© ......