http://www.cnblogs.com/yinzhenzhixin/archive/2009/01/07/1371064.html
ÔÚSQLÓï¾äÖУ¬UNION¹Ø¼ü×Ö¶àÓÃÀ´½«²¢ÁеĶà×é²éѯ½á¹û(±í)ºÏ²¢³ÉÒ»¸ö½á¹û(±í)£¬¼òµ¥ÊµÀýÈçÏ£º
SELECT [Id],[Name],[Comment] from [Product1]
UNION
SELECT [Id],[Name],[Comment] from [Product2]
ÉÏÃæµÄ´úÂë¿ÉÒÔʵÏÖ½«´ÓProduct1ºÍProduct2Á½ÕűíºÏ²¢³ÉÒ»¸ö±í£¬Èç¹ûÄúÖ»ÊÇÏ£ÍûºÏ²¢Á½ÕűíÖзûºÏÌØ¶¨Ìõ¼þµÄ¼Ç¼ÒÖ»òÊǺϲ¢Á½Õűí¸÷×ÔµÄǰNÌõ¼Ç¼£¬ÄÇôÄúµÄ´úÂë¿ÉÄÜ»áÏñÏÂÃæÕâÑùд£º
SELECT [Id],[Name],[Comment] from [Product1] WHERE LEN([Name]) > 5
UNION
SELECT [Id],[Name],[Comment] from [Product2] WHERE [Id] IN (11,20) AND [Comment] IS NOT NULL
SELECT TOP N [Id],[Name],[Comment] from [Product1]
UNION
SELECT TOP N [Id],[Name],[Comment] from [Product2]
This is so easy£¡µ«ÊǼÙÈçÄúÏ£Íû´Ó°üº¬Type×ֶεÄij±íÖиù¾ÝType·Ö±ðËæ»úɸѡNÌõ¼Ç¼²¢½«½á¹ûºÏ²¢³ÉÒ»ÕÅ±í£¬Äú¿ÉÄÜ»áÏñÏÂÃæÕâÑùд£º
SELECT TOP N [Id],[Name],[Comment] from [Product] WHERE [Type]='TYPE1' ORDER BY NEWID()
UNION
SELECT TOP N [Id],[Name],[Comment] from [Product] WHERE [Type]='TYPE2' ORDER BY NEWID()
UNION
SELECT TOP N [Id],[Name],[Comment] from [Product] WHERE [Type]='TYPE3' ORDER BY NEWID()
UNION
SELECT TOP N [Id],[Name],[Comment] from [Product] WHERE [Type]='TYPE4' ORDER BY NEWID()
UNION
SELECT TOP N [Id],[Name],[Comment] from [Product] WHERE [Type]='TYPE5' ORDER BY NEWID()
UNION
SELECT TOP N [Id],[Name],[Comment] from [Product] WHERE [Type]='TYPE6' ORDER BY NEWID()
UNION
SELECT TOP N [Id],[Name],[Comment] from [Product] WHERE [Type]='TYPE7' ORDER BY NEW