日期:2014-05-16  浏览次数:20723 次

mysql如何多表联合查询并分页
比如有两个表a,b.结构如下
a: id ,name; b: cid,title.
当然还有其他的字段。
想在a,b中在name,title中搜索关键字key,
输出以这样的id,name两列.
怎样才能这两个表进行搜索,并且是可以通过limite来分页的.

------解决方案--------------------
SQL code
select * from (
    select id,name
    from a
    union all
    select cid,title
    from b
) t
where name like '%key%'
order by id
limit 100,10

------解决方案--------------------
探讨

SQL code
select * from (
select id,name
from a
union all
select cid,title
from b
) t
where name like '%key%'
order by id
limit 100,10

------解决方案--------------------
SQL code
select * from (
select id,name 
from a
union all
select cid,title 
from b)r
where name like '%KEY%'
order by id
limit 100,10;