Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 从同一个表中获取两个不同值的post ID_Mysql - Fatal编程技术网

Mysql 从同一个表中获取两个不同值的post ID

Mysql 从同一个表中获取两个不同值的post ID,mysql,Mysql,我有两张桌子: 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和ww),value是(ggg和ttt)。 我用的是: SELECT t1.* FROM tabel1 t1 JOIN tabel2 t2 ON t1.

我有两张桌子:

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和ww),value是(ggg和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')
但我只得到了这个: 表1

  id name address
   1  ss    aaaa
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')