首先你的数据当中必须有一个id,一个uid查询uid为1,2,3分别都几条:(假定表名为'user',表中只有两个字段,分别为id和uid) select id,count(uid) from user group by uid having uid=1 or uid=2 or uid =3; 查询uid为1的第一条: select * from user where uid=1 limit 1;
select * from tbl_name a where (select count(*) from tbl_name where uid=a.uid and id<a.id) = 1 and uid in (1,2,3)
每个条件只取一条: select * from tt where uid in(1,2,3) group by uid ;
select a.* from table a where 1> (select count(1) from table b where a.id = b.id and a.id > b.id ) and a.uid in (1,2,3)
select id,count(uid) from user group by uid having uid=1 or uid=2 or uid =3;
查询uid为1的第一条:
select * from user where uid=1 limit 1;
where (select count(*) from tbl_name where uid=a.uid and id<a.id) = 1 and uid in (1,2,3)
select * from tt where uid in(1,2,3) group by uid ;