【MySQL作业】外连接查询——美和易思外连接查询应用习题

点击打开所使用到的数据库>>>


1、使用左接获取所有客户的基本信息以及订购信息,要求输出客户姓名、电话、订单 ID 和下单时间。

由于需要获取所有客户的基本信息,如果采用左连接加以实现,必须从左至右依次连接客户表和订单表,此时客户表将作为左表。

select cName 姓名 , ordersID 订单 ID, ordersDate 下单日期 from customer c left join orders o on c.customerID=o.customerID


2、使用右接获取所有客户的基本信息以及订购信息,要求输出客户姓名、电话、订单 ID 和下单时间。

由于需要获取所有客户的基本信息,如果采用右连接加以实现,必须从左至右依次连接订单表和客户表,此时客户表将作为右表。

select cName 姓名 , ordersID 订单 ID, ordersDate 下单日期
from orders o right join customer c on o.customerID=c.customerID

发布了112 篇原创文章 · 获赞 182 · 访问量 19万+

猜你喜欢

转载自blog.csdn.net/weixin_44893902/article/details/105695215