我有两张桌子:
tabel1
id name address
1 ss aaaa
2 ee wwww
tabel2
id tid key value
1 1 rr ggg
2 1 ww ttt
3 2 rr ggg
4 2 ww ttt
我想获取tabel1的值,其中“key”是(rr AND ww),值是(ggg AND ttt)。 我正在使用这个:
SELECT t1.* FROM tabel1 t1 JOIN tabel2 t2 ON t1.id = t2.tid WHERE (t2.key = 'rr' AND t2.value ='ggg') OR (t2.key='ww' AND t2.value = 'ttt')
但我只得到这个: tabel1
id name address
1 ss aaaa
答案 0 :(得分:0)
SELECT t1.*,t2.* FROM tabel1 t1 JOIN tabel2 t2 ON t1.id = t2.tid WHERE (t2.key = 'rr' AND t2.value ='ggg') OR (t2.key='ww' AND t2.value = 'ttt')