select p.prod_name,ifnull(x.orders,0). #用ifull去将null改成0 from Products as p left join (select prod_id,count(prod_id) as orders from OrderItems group by prod_id) as x on x.prod_id = p.prod_id order by p.prod_name;