表A
----------------------
| a_id | a_name | a_tt|
-----------------------
| 1 | test1 | 2 |
-----------------------
| 2 | test2 | 3 |
-----------------------表B
----------------
| b_id | b_name|
----------------
| 1 | bb1 |
----------------
| 2 | bb2 |
----------------
| 3 | bb3 |
----------------表A中有上千条记录,a.a_tt 和 b.b_id 相等。我想查询表A中的记录a_tt=1、2、3的各10条。sql语句改怎么写呢?我只会写全部查出的语句
select a.*,b.b_name from a,b where a.a_tt=b.b_id;
----------------------
| a_id | a_name | a_tt|
-----------------------
| 1 | test1 | 2 |
-----------------------
| 2 | test2 | 3 |
-----------------------表B
----------------
| b_id | b_name|
----------------
| 1 | bb1 |
----------------
| 2 | bb2 |
----------------
| 3 | bb3 |
----------------表A中有上千条记录,a.a_tt 和 b.b_id 相等。我想查询表A中的记录a_tt=1、2、3的各10条。sql语句改怎么写呢?我只会写全部查出的语句
select a.*,b.b_name from a,b where a.a_tt=b.b_id;
select a.*,b.b_name from a,b where a.a_tt=b.b_id and a.a_tt=2 limit 10;
select a.*,b.b_name from a,b where a.a_tt=b.b_id and a.a_tt=3 limit 10;
from a,b
where a.a_tt=b.b_id and a.a_tt in (1,2,3)
group by a.a_tt
limit 10;
from a,b
where a.a_tt=b.b_id
and a.a_tt in (1,2,3)
and (select count(*) from a where a_tt=a.a_tt and a_tt in (1,2,3) and a_id<=a.a_id)<=10