首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

关于sql的多表联检

2012-09-06 
关于sql的多表联查现在有这样一个问题,有四张表,分别是A、B、C、D,里面都有相同的字段a、b、c、d、e,现在我想通过

关于sql的多表联查
现在有这样一个问题,有四张表,分别是A、B、C、D,里面都有相同的字段a、b、c、d、e,现在我想通过一个搜索功能查找出四张表里面某一相同字段的内容,查询采用模糊查询。比如说查找出A.a,B.a,C.a,D.a四张表的a字段里面有包含‘11’内容的所有记录。。

[解决办法]

SQL code
select * from A where A.a like '%11%'union allselect * from B where B.a like '%11%'union allselect * from C where C.a like '%11%'union allselect * from D where D.a like '%11%'
[解决办法]
SQL code
select * from (select * from Aunion all select * from Bunion all select * from Cunion all select * from D) twhere t.a like '%11%';
[解决办法]
SQL code
select  *from  (    select * from a union all select * from b union all select * from c union all select * from d)twhere   a like '%11%' 

热点排行