查询数据库没有重复 [英] Query database without duplicate
本文介绍了查询数据库没有重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个数据库表t1和t2,我想从第三个表t3到t1插入所有数据,而t1和t2都没有重复数据?请帮助
我的尝试:
Cherch理想的解决方案对于这个问题
i have two database tables t1 and t2 and i want to insert all data from a third table t3 to t1 without duplicate data already in both t1 and t2? Please help
What I have tried:
Cherch for ideal solution for this problem
推荐答案
假设所有3个表都有相同的字段,比如field1和field2,除了主键(如果有的话),
Assuming all the 3 tables have identical fields, say field1 and field2, except the primary keys if any,
INSERT INTO table1 (
SELECT * FROM table3 t3 WHERE NOT EXISTS (
(SELECT * FROM table1 t1 WHERE t1.field1=t3.field1 AND t1.field2=t3.field2)
OR
(SELECT * FROM table2 t2 WHERE t2.field1=t3.field1 AND t2.field2=t3.field2)
))
这篇关于查询数据库没有重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文