SELECT a.prod_name,b.order_num
FROM Products a
left join OrderItems b on a.prod_id=b.prod_id
union
SELECT a.prod_name,b.order_num
FROM Products a
left join OrderItems b on a.prod_id=b.prod_id
where a.prod_id is null
FROM Products a
left join OrderItems b on a.prod_id=b.prod_id
union
SELECT a.prod_name,b.order_num
FROM Products a
left join OrderItems b on a.prod_id=b.prod_id
where a.prod_id is null
order by prod_name
# orderby针对select后面的内容排序的,如果最后一行是a.prod_name则会报错,因为prod_id为空的时候,a.prod_name关联不到。