Answer the question
In order to leave comments, you need to log in
How to select two records of a certain category from mysql database?
there is a table with goods.
You need to select the first two records of each category with one query,
i.e. in the end it should turn out
PS If possible in yii2 format, if not, a simple mysql query will also go, I'll figure it out there =)
Answer the question
In order to leave comments, you need to log in
Select t1.cat_id, t1.id, t2.* from
(Select cat_id, min(id) from table group by cat_id
UNION
Select cat_id, min(id) from table
where id not in (Select min(id) from table group by cat_id) group by cat_id) t1
left join table t2 on t1.id = t2.id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question