Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.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,我想同步两列(一个表,两列) 例如: A-1参考了B-2、3、4,但A-2只参考了B-1 如何使用mysql查询添加B-1参考B-3和B-4 A B ------- 1 2 1 3 1 4 2 1 3 1 4 1 5 6 5 7 6 5 7 5 我想你想要这个: insert into t(a, b) select b, a from t where not exists (select 1 from

我想同步两列(一个表,两列)

例如:

A-1参考了B-2、3、4
,但
A-2只参考了B-1

如何使用mysql查询添加B-1参考B-3和B-4

A    B 
-------
1    2
1    3
1    4
2    1
3    1
4    1
5    6
5    7
6    5
7    5
我想你想要这个:

insert into t(a, b)
    select b, a
    from t
    where not exists (select 1 from t t2 where t2.a = t.b and t2.b = t.a);

这将从两个方向将所有对放入表中。

发布您迄今为止尝试的查询。所以这不是免费的编码服务。我们可以帮助您解决代码中遇到的问题,但我们不会为您编写代码。