I am selecting some data using the following query. It works well. Now I set the limit as 15. I am collecting data from various sub categories. Now the data getting is a total of 15 from the whole categories. Is there any way to get 15 data on each sub category in this single query using CASE
or IF
for example now it gives mobile - 5, computer - 4 and camera - 6
I need Mobile - 15, camputer - 15 and camera - 15
My Query is
SELECT
count_sum,
id,
NAME,
url,
price,
main_url,
sub_url,
image
FROM
(
SELECT
SUM(product_count.count) AS count_sum,
product.id,
product. NAME,
product.url,
product.price,
main_cat.main_url,
sub_cat.sub_url
FROM
product_count
JOIN product ON product_count.id_fk = product.id
JOIN main_cat ON product.main_id = main_cat.main_id
JOIN sub_cat ON product.sub_id = sub_cat.sub_id
WHERE
product_count.product_status = 'active'
AND product. STATUS = 'active'
GROUP BY
product_count.id_fk
) product
JOIN image_details ON image_details.id_fk = product.id
WHERE
image_details.featured = 'yes'
GROUP BY
product. NAME
ORDER BY
count_sum DESC
LIMIT 15
I checked this question. But it didn't work for me. Actually I didn't get the workflow. Can some please help me? I am beginer in these kind of codes. Please help