SQL多个表实现联合查询

select LineId,Id,Country from Domestic
union all
select LineId,Id,Country from Freedom
-- 联合查询Domestic,Freedom表的LineId,Id,Country all代表不去除反复
--功能:[SQL语句] UNION [SQL语句]将两个语句中选择的同一列中的不同的值筛选出来

SELECT<表1>.<列名> ,<表2><列名>FROM<表1>OUTER JOIN<表2> ON<表1>.<列>=表2>.<列名>
--功能:实现两个表的外连接

Select Domestic.LineId,Freedom.LineId from Domestic,Freedom where Domestic.Sames=Freedom.Sames
Select Domestic.LineId,Freedom.LineId FROM Domestic inner join Freedom on Freedom.Sames=Domestic.Sames
--功能:实现两个表的内连接 把Domestic,Freedom两个表用Domestic.Sames=Freedom.Sames关联起来显示Domestic.LineId,Freedom.LineId
------------------------
我的数据库表是这种:table0101,table0102,table0103,.......各个表有同样的结构,我想用sql语句从查询分析器里导出来,有沒有办法能够一次导出,语句要返回一个结果集.
用union all就能够实现:

select * from table0101
union all
select * from table0102
union all
select * from table0103
union all
select * from table0104
....

****************
补充:假设想去掉反复记录的话,把union all 改成 union就能够了
---
以上,希望对你有所帮助。

原文地址:https://www.cnblogs.com/mfryf/p/3437466.html