我有一個查詢不等於搜尋有LeftJoin
Select
m.name
from machines m
innerJoin config c ON m.cod = c.cod
--> where (c.category = 'BIOS' and c.val = 'System')
--> and (c.category = 'Users' and c.val = 'Jonas')
group by c.cod
* MACHINES ---------------- +
| key | name | cod |
* ------ + ------- + ------ +
| 1 | M1 | 23 |
| 2 | M2 | 26 |
| 3 | M3 | 27 |
+ ------ + ------- + ------ +
* CONFIG --------------------------- +
| key | category | cod | val |
+ ------ + -------- + ----- + ------ +
| 1 | BIOS | 23 | System |
| 2 | Users | 23 | Jonas |
| 3 | Users | 23 | Maria |
| 4 | BIOS | 26 | System |
| 5 | Users | 26 | Jonas |
| 6 | BIOS | 27 | System |
| 6 | Users | 27 | Ana |
+ ------ + -------- + ----- + ------ +
我得到
* RESULT -- +
| name |
+ --------- +
| M1 |
| M2 |
+ --------- +
其偉大的「平等」的搜索,但我不知道我該怎麼辦「不等於」搜索此查詢。
我想:
Select
m.name
from machines m
innerJoin config c ON m.cod = c.cod
--> where (c.category = 'BIOS' and c.val <> 'System')
--> or (c.category = 'Users' and c.val <> 'Jonas')
group by c.cod
,但仍然得到機「M1」,與價值「瑪麗亞」匹配濾波器
我需要做的與此過濾器的結果領域:
* RESULT -- +
| name |
+ --------- +
| M3 |
+ --------- +
我該怎麼辦呢?
工作! ,現在不需要使用GROUP_CONCAT或有,就是我認爲,子查詢是不可避免的 – israel
它可以與具有條件來完成。 (http://sqlfiddle.com/#!9/f2a480/4/1) – xQbert