2

上記のスキーマに基づいて、英語フランス語を話すすべてのユーザーを取得しようとしています。どうすればこれを達成できますか?

私は次のようなもので試しました:

SELECT * FROM User
INNER JOIN UserLanguage on User.idUser = UserLanguage.idUser
INNER JOIN Language on UserLanguage.idLanguage = Language.idLanguage
WHERE Language.name = "FR" AND Language.name = "EN"

SQL スキーマ

4

7 に答える 7

2
SELECT * 
FROM User
WHERE 2 = (SELECT COUNT(*)
            FROM UserLanguage 
            INNER JOIN Language
              ON UserLanguage.idLanguage = Language.idLanguage
                 AND (Language.name = 'FR' OR Language.name = 'EN')
            WHERE User.idUser = UserLanguage.idUser)
于 2013-10-14T14:14:45.320 に答える
1
 SELECT * FROM User
    INNER JOIN UserLanguage on User.idUser = UserLanguage.idUser
    INNER JOIN Language on UserLanguage.idLanguage = Language.idLanguage
 WHERE Language.name = "FR" AND Language.name = "EN"

を変更するだけです。

 WHERE Language.name = "FR" AND Language.name = "EN"

 WHERE (Language.name = "FR" OR Language.name = "EN")
于 2013-10-14T14:19:21.290 に答える
0
SELECT *
FROM Users u INNER JOIN UserLanguage ul
ON u.idUser = ul.idUser JOIN Language l
ON ul.idLanguage = l.idLanguage
WHERE l.LanguageName IN ('EN', 'FR')
ORDER BY u.idUser
于 2013-10-14T14:12:28.800 に答える
0

UserLanguage テーブルをそれ自体に結合する必要があります。たとえば、次のようになります。

SELECT T1.idUser 
FROM UserLanguage AS T1
INNER JOIN UserLanguage AS T2
ON T1.idUser=T2.idUser
WHERE T1.idLanguage='EN'
AND T2.idLanguage='FR'
于 2013-10-14T14:15:13.200 に答える