Using PHP, is it possible to select multiple rows from one table, in a MySQL database, with different WHERE clauses having a specific LIMIT for each WHERE clause.
For example:
SELECT * FROM the_table WHERE color = 'blue' LIMIT 5 OR color = 'red' LIMIT 10
I know the above statement does not work. But is there a way to do this with a single call to the database?
You can use a UNION, if I understand your post correctly:
(SELECT * FROM the_table WHERE color = 'blue' LIMIT 5)
UNION ALL
(SELECT * FROM the_table WHERE color = 'red' LIMIT 10)
SELECT * FROM the_table WHERE color = 'blue' LIMIT 5
UNION
SELECT * FROM the_table WHERE color = 'red' LIMIT 10 ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With