有时在查询语句中有or等出现时,如果查询速度比较慢的话,可以考虑用union all来替换,优化查询。 如下:
select name from tableA where 条件1
union all
select name from tableB where 条件2
如果要加limit,可以这样写
select c.* from (
select name from tableA where 条件1
union all
select name from tableB where 条件2
) as c limit 0,40