Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.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 按联接表值选择_Mysql_Sql - Fatal编程技术网

Mysql 按联接表值选择

Mysql 按联接表值选择,mysql,sql,Mysql,Sql,我加入了一些表,这样我就有了这样的结果表 IDnameval 1n1false 1n2true 1N3真 第二条真理 2N2真的 2n3真 3n1false 3N2真 3n3真 一个可能的解决方案是 select distinct id from yourTable t1 join yourTable t2 on t1.id = t2.id where t1.name = n1 and t1.val = 'true' and t2.name = n

我加入了一些表,这样我就有了这样的结果表


IDnameval
1n1false
1n2true
1N3真
第二条真理
2N2真的
2n3真
3n1false
3N2真
3n3真

一个可能的解决方案是

select  distinct id
from    yourTable t1
join    yourTable t2
on      t1.id = t2.id
where   t1.name = n1 and t1.val = 'true' and
        t2.name = n2 and t2.val = 'true';

一个可能的解决办法是

select  distinct id
from    yourTable t1
join    yourTable t2
on      t1.id = t2.id
where   t1.name = n1 and t1.val = 'true' and
        t2.name = n2 and t2.val = 'true';