I have two tables, I want to build one query to select only results from orders where the quantity is not fulfilled by table deliveries:
table orders:
id item quantity
1 a 15
2 b 5
3 c 6
table deliveries:
id order_id quantity
1 2 3
2 2 1
3 2 1
4 3 3
I want it something like this:
SELECT * FROM `orders`
WHERE `quantity`>(SELECT SUM(`quantity`)
FROM `deliveries`
WHERE `order_id`=orders.id);
result should be something like this:
id item quantity
1 a 15
3 c 6