Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.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_Database - Fatal编程技术网

比较MySql表

比较MySql表,mysql,database,Mysql,Database,我有两个表,每个表中都有数字: 对于expamle-> 表1: 1. 2. 3. 4. 五, 表2: 5. 3. 一, 我试图编写一个查询,显示表1中的任何值,但不在表2中(反之亦然)。这些数字可以是任意顺序,并且都是主键。使用进行两次单独的查询,然后将其输出与组合。使用进行两次单独的查询,然后将其输出与组合。如果您编辑问题并给出表模式,我可以给出更清楚的答案。 现在我只是假设 select t1.* from table1 t1 left join table2 t2 on t2.id=t1

我有两个表,每个表中都有数字:

对于expamle->

表1: 1. 2. 3. 4. 五,

表2: 5. 3. 一,


我试图编写一个查询,显示表1中的任何值,但不在表2中(反之亦然)。这些数字可以是任意顺序,并且都是主键。

使用进行两次单独的查询,然后将其输出与组合。

使用进行两次单独的查询,然后将其输出与组合。

如果您编辑问题并给出表模式,我可以给出更清楚的答案。 现在我只是假设

select t1.* 
from table1 t1
left join table2 t2 on t2.id=t1.id
where t2.id is null
备选方案:

select t1.* 
from table1 t1
where t1.id not in (select id from table2)

如果你编辑你的问题并给出你的表格模式,我可以给出更清晰的答案。 现在我只是假设

select t1.* 
from table1 t1
left join table2 t2 on t2.id=t1.id
where t2.id is null
备选方案:

select t1.* 
from table1 t1
where t1.id not in (select id from table2)

(和另一个方向相反)谢谢你。正是我想要的。谢谢。正是我想要的。