Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.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
Php 如何从mysql连接结果中删除匹配行并显示不匹配行?_Php_Sql_Mysql_Join - Fatal编程技术网

Php 如何从mysql连接结果中删除匹配行并显示不匹配行?

Php 如何从mysql连接结果中删除匹配行并显示不匹配行?,php,sql,mysql,join,Php,Sql,Mysql,Join,是否有任何方法可以从MySQL连接查询中删除匹配的行。 实际上,我有两个表,其中存储了pub_id和post_id,这两个表都很常见。 当我查询表1和表2中的所有匹配行时,不应列出结果,而只应列出不匹配的行。查询返回仅存在于两个表之一中的行: SELECT * FROM Table1 t1 WHERE NOT EXISTS (Select 1 from Table2 t2 Where t1.pub_id = t2.pub_id

是否有任何方法可以从MySQL连接查询中删除匹配的行。 实际上,我有两个表,其中存储了pub_id和post_id,这两个表都很常见。
当我查询表1和表2中的所有匹配行时,不应列出结果,而只应列出不匹配的行。

查询返回仅存在于两个表之一中的行:

SELECT *
FROM Table1 t1
WHERE NOT EXISTS (Select 1 from Table2 t2 
                 Where t1.pub_id = t2.pub_id
                AND t1.post_Id = t2.post_id)
UNION ALL
SELECT *
FROM Table2 t1
WHERE NOT EXISTS (Select 1 from Table1 t2 
                 Where t1.pub_id = t2.pub_id
                AND t1.post_Id = t2.post_id)

你需要这样的东西:

    SELECT * FROM tablea AS a
   RIGHT  JOIN tableb AS o ON a.id = o.id WHERE a.pub_id IS NULL and a.post_id is null 
UNION    
SELECT * FROM tablea AS a
   LEFT  JOIN tableb AS o ON a.id = o.id WHERE o.pub_id IS NULL and o.post_id is null 

我运行了这个查询,但它没有返回确切的结果,从wp_posts as posta中选择ID作为postlist,如果不存在,从wp_publication中选择*作为pub,其中pub.publication_ID=posta.ID和pub.post_ID=posta.ID