题解 | #返回产品名称和与之相关的订单号#
返回产品名称和与之相关的订单号
https://www.nowcoder.com/practice/c369a759436a4e8b80baa9c39e9adf18
#该题要求使用outer join,但是由于mysql不支持outer join,所以只能使用left join +right join实现全联结 (select p.prod_name, oi.order_num from Products p left join OrderItems oi on p.prod_id = oi.prod_id) union (select p.prod_name, oi.order_num from Products p right join OrderItems oi on p.prod_id = oi.prod_id) order by prod_name #UNION 操作符会自动合并两个结果集的列名,所以不用给两个select语句起别名