I am trying to select three random rows from a table, where their combined item_price
column is less than a desired amount.
Imagine you have an
here is another solution:
SELECT t1.item_id as id1, t2.item_id as id2, t3.item_id as i3
FROM items t1, items t2, items t3
WHERE
t1.item_id <> t2.item_id and
t1.item_id <> t3.item_id and
t2.item_id <> t3.item_id and
(t1.item_price + t2.item_price + t3.item_price) <= 300
order by rand()
limit 1
optionally you can filter by minimal sum