我有3個表:冠軍,角色,champs_to_rolesWHERE子句需要多個值?
的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或者他們都是
如何獲取我需要的內容?
感謝很多:)
感謝解決我的問題。如果我必須增加所需值的數量,您的解決方案非常靈活;) –