Hello,
I want to run a query to fetch 10 rows from database with the ‘category_id’ parameter set, and fall back if there are not 10 rows from the mentioned category to fetch the missing rows from the same table without category_id.
How can you calculate a difference with php?
Right now I call this query:
(SELECT asin FROM products $where ORDER BY $order_by LIMIT 10)
UNION
(SELECT asin FROM products WHERE site_id = $site_id ORDER BY $order_by LIMIT 10)
And then use splice_array in php to get the first 10.
Which would be more elegant way to do this with mysql?
Thanks for help