将Intersect从Oracle转换为MySQL

时间:2015-07-10 04:33:52

标签: mysql oracle

您好我试图将以下内容从oracle转换为Mysql,因为Mysql不支持使用INTERSECT。我试图做几次加入但仍然没有运气。 Oracle Query:

select DISTINCT company_name from employee
inner join works on
works.Lastname=employee.Lastname AND
works.Firstname=employee.Firstname AND
works.MidInitial=employee.MidInitial
where employee.city='New York'
INTERSECT
select DISTINCT company_name from employee
inner join works on
works.Lastname=employee.Lastname AND
works.Firstname=employee.Firstname AND
works.MidInitial=employee.MidInitial
where employee.city='Seattle'

谢谢!

1 个答案:

答案 0 :(得分:0)

在您的情况下(所有行都是唯一的),以下方法应该有效:

SELECT x.company_name FROM
(select DISTINCT company_name from employee
 inner join works on
 works.Lastname=employee.Lastname AND
 works.Firstname=employee.Firstname AND
 works.MidInitial=employee.MidInitial
 where employee.city='New York') x
INNER JOIN
(select DISTINCT company_name from employee
 inner join works on
 works.Lastname=employee.Lastname AND
 works.Firstname=employee.Firstname AND
 works.MidInitial=employee.MidInitial
 where employee.city='Seattle') y
USING (company_name)