I'm stuck with query. The scenario is like this: - I need to select max 4 product_name for each category. - I'm using this query but it doesn't work the way I need -each cat_id with product_name limit 4
the result will contain 4 lines from the whole query output.
$sql_course = "SELECT * FROM product WHERE cat_id IN('".$brand_filter."') ORDER BY cat_id LIMIT 4";
i want this
cat_id1- product1
cat_id1- product2
cat_id1- product3
cat_id1- product4
cat_id2- product5
cat_id2- product6
cat_id2- product7
cat_id2- product8
限制正在影响您的输出,因为它只带来四个记录。
$sql_course = "SELECT * FROM product WHERE cat_id IN('".$brand_filter."') GROUP BY cat_id ORDER BY cat_id LIMIT 4";
我想这会奏效,请尝试检查结果。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.