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);
这将从两个方向将所有对放入表中。发布您迄今为止尝试的查询。所以这不是免费的编码服务。我们可以帮助您解决代码中遇到的问题,但我们不会为您编写代码。