关于sql的多表联检
关于sql的多表联查
现在有这样一个问题,有四张表,分别是A、B、C、D,里面都有相同的字段a、b、c、d、e,现在我想通过一个搜索功能查找出四张表里面某一相同字段的内容,查询采用模糊查询。比如说查找出A.a,B.a,C.a,D.a四张表的a字段里面有包含‘11’内容的所有记录。。
------解决方案--------------------
现在有这样一个问题,有四张表,分别是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 all select * from B where B.a like '%11%' union all select * from C where C.a like '%11%' union all select * from D where D.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 ) t where 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)t where a like '%11%'