SQL查询-JOIN和UNION

时间:2019-12-30 16:44:16

标签: mysql sql

我无法回答这个问题: 显示按公司名称排序的为巴黎客户进行销售的雇员的姓氏和客户公司(COMPANY)。

这是我的代码:

select NAME from EMPLOYEES inner join SALES on EMPLOYEES.NO_EMPLOYEES = SALE.NO_EMPLOYEES
union
select COMPANY from SALES inner join CLIENTS on SALES.CODE_CLIENT = CLIENTS.CODE_CLIENT where CLIENTS.CITY = 'Paris'

问题是工会只给我一列...如何解决这个问题?

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我认为您只需要两个联接:

select e.NAME, c.COMPANY
from EMPLOYEES e join
     SALES s
     on e.NO_EMPLOYEES = s.NO_EMPLOYEES join
     CLIENTS c
     on s.CODE_CLIENT = c.CODE_CLIENT
where c.CITY = 'Paris';