Is there a way to combine these queries so that I get a distinct name, then the quantity for today, tomorrow, and the day after tomorrow
select name, SUM(qty) as qty_today, 0 as qty_tomororow, 0 as qty_om
from order_item
where delivery_date = '2011-11-22'
group by name
union all
select name, qty as qty_today, SUM(qty) as qty_tomororow, 0 as qty_om
from order_item
where delivery_date = '2011-11-23'
group by name
union all
select name, 0 as qty_today, 0 as qty_tomororow, SUM(qty) as qty_om
from order_item
where delivery_date = '2011-11-24'
group by name
UPDATE
Given the table
name, qty, delivery_date
Chicago, 1, 2011-11-22
New York, 2, 2011-11-22
Chicago, 3, 2011-11-23
I would expect
Chicago, 1, 3, 0
New York, 1, 0, 0
If you are trying to combine all of them in one dataset you can try this,
This would work in TSQL (MS SQL), hopefully it’s the same syntax in MySql