我需要显示所有艺术家的名字,每个艺术家至少有一名女性成员。
Members表如下所示:
Members
-------
MemberID, Firstname, Lastname, Address, Gender
艺术家表格如下:
Artists
-------
ArtistID, Artistname, City
使用xRefArtistsMembers表关联表,如下所示:
xRefArtistsMembers
------------------
MemberID, ArtistID
我已经制定了以下子查询:
select
ar.artistname from artists ar
where
ar.artistid in
(
(
select
x.artistid
from
xrefartistsmembers x
)
in
(
select
m.memberid
from
members m
)
);
不编译。同样,我的问题是:我需要显示所有艺术家的名字,每个艺术家至少有一名女性成员。仅使用子查询。
答案 0 :(得分:1)
尝试
SELECT *
FROM artists a
WHERE EXISTS
(
SELECT *
FROM xRefArtistsMembers x
WHERE artistid = a.artistid
AND EXISTS
(
SELECT *
FROM members
WHERE memberid = x.memberid
AND gender = 'female'
)
)
这是 SQLFiddle 演示