将多个JOINS重写为SUBQUERIES

时间:2013-12-09 23:27:30

标签: sql

我需要在我的艺术家表中找到代表特定乐队的所有销售人员的姓名。

我的表格重申了以下内容:

销售人员

SalesID,名字,姓氏

艺术家

ArtistID,ArtistName

成员

MembersID,名字,姓氏。 SalesID

MembersID和Artists表与下表相关:

xRefArtistsMembers

ArtistID,MemberID

我制定了以下查询:

 select sp.firstname, sp.lastname from salespeople sp
 inner join members m on (m.salesid = sp.salesid)
 inner join xrefartistsmembers x on (x.memberid = m.memberid)
 inner join artists a where a.artistname = "The Bullets";

他们也是用子查询做这个的方法吗?

2 个答案:

答案 0 :(得分:1)

试试这个:

select sp.firstname, sp.lastname from salespeople sp
inner join members m on (m.salesid = sp.salesid)
inner join xrefartistsmembers x on (x.memberid = m.memberid)
inner join artists a on a.artistID = x.artistID
where a.artistname = "The Bullets"

答案 1 :(得分:0)

你对艺术家的内部联系不应该有on条款,而不是你的where条款吗?

inner join artists a where a.artistname = "The Bullets";

将是

inner join artists a on a.artistid = x.artistid
where artists.artistname = "The Bullets";