我有 3 张桌子:冠军、角色、champs_to_roles
champs_to_roles 表如下所示:
|ID_champ|ID_role|
----------------
| 2| 2|
| 4| 5|
| 5| 3|
| 3| 2|
| 1| 1|
| 1| 2|
我正在尝试选择 ID_champ WHERE ID_role = 1 AND ID_role = 2。
此时我有以下代码:
SELECT DISTINCT `c`.`name`
FROM `champions` AS c,
(
SELECT `ID_champ`
FROM `champs_to_roles`
WHERE `ID_role` IN(1,2)
) AS r
WHERE `r`.`ID_champ` = `c`.`ID`
但是,这会返回我 ID_champ ID_role = 1 或 Id_role = 2 或两者
我怎样才能得到我需要的东西?
非常感谢 :)