Ask a question about php + mysql to query data in a table with the condition uid in (, 3 ). Then, all the values that meet uid = 1, 2, or 3 are queried.
How can we get only one entry per condition?
For example, if the uid is 1, 2, and 3 respectively, you can use SQL to query only the first entry of uid 1, the first entry of uid 2, and the first entry of uid 3.
Reply to discussion (solution)
First, you must have an id and uid in your data.
Query the numbers of uid 1, 2, and 3 respectively: (assume that the table name is 'user', and the table has only two fields, id and uid, respectively)
select id,count(uid) from user group by uid having uid=1 or uid=2 or uid =3;
Query the first entry with uid 1:
select * from user where uid=1 limit 1;
You can obtain one query result set in the group.
Select * from tbl_name a where (select count (*) from tbl_name where uid = a. uid and id Each condition has only one entry:
Select * from tt where uid in (1, 2, 3) group by uid;
Select. * from table a where 1> (select count (1) from table B where. id = B. id and. id> B. id) and. uid in (1, 2, 3)
Select top 1 * from table group by id
Group by can be implemented