多表查询合并记录,将两个表的查询结果合并到一个表里
				
									
					
					
						 | 
						
							
							tercel 
							
							
								2010年12月27日 1:2
								本文热度 4766
							
							 
						 | 
					
					
				 
				 
 
数据库 Translate-SQL 中 的运算符,将两个或更多查询的结果组合为单个结果集,该结果集包含联合查询中的所有查询的全部行。这与使用联接组合两个表中的列不同。使用 UNION 组合两个查询的结果集的两个基本规则是:   1 、 所有查询中的列数和列的顺序必须相同。   2 、 数据类型必须兼容。    例句:   select top 100 aa.keyno,aa.commtype from comminfo aa    union all   select bb.userno,bb.corpname from userinfo bb   将comminfo表和userinfo表中的字段合成一个结果集 
select tbl,id,title from( select ('A')as tbl,id,title from A where title like '%关键字%' union all select ('B')as tbl,id,name as title from B where name like '%关键字%' ) 
将表2中符合条件的记录插入到表1里 
insert into 表1(字段1,字段2,.....) select 字段1,字段2,..... from 表2 where 条件   | 
该文章在 2010/12/27 1:02:21 编辑过