I’d like to select order items from all orders with a specific item. In SQL I’d do it like this:
SELECT DISTINCT i.id, i.name, order.name
FROM items i
JOIN orders o ON i.order_id=o.id
WHERE o.id IN (
SELECT o2.id FROM orders o2
JOIN items i2 ON i2.order_id=o2.id AND i2.id=5
)
AND i.id != 5
ORDER BY o.orderdate DESC
LIMIT 10
How would I do this query with the query builder?
This is how I would try it:
I didn’t test this of course, and made some assumptions about your models. Possible problems:
Concluding, this may not work first time, but will surely put you on the right track. Do tell us the final 100% correct answer afterwards.