select * from a where userid=1 limit 2 union all select * from a where userid=2 limit 4这样呢
select * from a a1 where 2 >(select count(*) from a a2 where a1.userid=a2.userid and a1.id<a2.id) and userid in (1,2)
测试过确实是这样 select * from (select * from a where userid=1 limit 2 union all select * from a where userid=2) tmp limit 4
select * from a where userid=1 limit 2 union all select * from a where userid=2 limit 2 //括号除掉就只能查出一条结果 为什么?这条语句相当于' select * from ( select * from a where ..... limit 2 union all select * from a where ...... limit 2 ) limit
分别查询查一次,看看结果select * from a where userid=1 limit 2 union all select * from a where userid=2 limit 2
select *
from a a1
where 2 >(select count(*) from a a2 where a1.userid=a2.userid and a1.id<a2.id)
and userid in (1,2)
//括号除掉就只能查出一条结果 为什么?这条语句相当于'
select * from
( select * from a where ..... limit 2 union all select * from a where ...... limit 2 )
limit
union all
select * from a where userid=2 limit 2