从另一个数据库表中删除相同的值 [英] Delete same values from another db table
本文介绍了从另一个数据库表中删除相同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个具有相同结构的数据库。我如何删除db2.table中存在的记录,它存在于db2.table中?
db1表:a - 1,a - 2,b - 1,c - 1
db2表:a - 1,a - 2,c - 1,c - 2
< b-1
此查询无效
p> DELETE t1
从表t1
JOIN db2.table t2
WHERE t1.PrdID = t2 .PrdID AND t1.CategoryID = t2.CategoryID
它给我错误
在t1附近:语法错误:
$ b b
db2附加到db1
解决方案
请尝试此操作,然后再删除,测试子查询
DELETE FROM table1 WHERE(您的列)IN(SELECT(your_column)FROM table2)
b $ b
I have two databases with the same structure. How can i delete records from db1.table, that exists in db2.table?
db1 table: a - 1, a - 2, b - 1, c - 1
db2 table: a - 1, a - 2, c - 1, c - 2
result: b - 1
Update:
This query doesn't work
DELETE t1
FROM table t1
JOIN db2.table t2
WHERE t1.PrdID = t2.PrdID AND t1.CategoryID=t2.CategoryID
It gives me error
near "t1": syntax error:
db2 is attached to db1
解决方案
Try this, before delete, test the subquery,
DELETE FROM table1 WHERE (your column) IN (SELECT (your_column) FROM table2)
(Not tested)
这篇关于从另一个数据库表中删除相同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文