数据表合并(急)
两个数据表
A
id name
1 aaa
2 bbb
9 ccc
B
id name
1 aaa
3 ddd
9 ccc
要把A中有B中没有的加到B中。id不能重
最好用标准SQL实现(我用的是MySQL)
另外,我试着用
insert into B select * from A where id not in (select id from B)
提示语法错误
问题点数:80、回复次数:10Top
1 楼scmail81(琳·风の狼(修罗))回复于 2006-03-06 20:28:18 得分 0
try:
insert into B select * from A where not exists(select 1 from B where A.id=B.id)Top
2 楼my49cn()回复于 2006-03-06 20:35:06 得分 0
还是
#1064 - You have an error in your SQL syntax.Top
3 楼xeqtr1982(Visual C# .NET)回复于 2006-03-06 20:39:36 得分 0
在SQL中,没问题啊Top
4 楼my49cn()回复于 2006-03-06 20:52:16 得分 0
我在phpmyadmin里运行的时候就是不行啊
MySQL 返回:
#1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'exists(select 1 from B where A.id=B.id)' at line 1
Top
5 楼sunlight539(阿不)回复于 2006-03-06 20:58:33 得分 0
insert into b from a
where a.id not in (select id from b )Top
6 楼my49cn()回复于 2006-03-06 21:11:02 得分 0
一样不行Top
7 楼lxzm1001(*~悠悠蓝星梦~*)回复于 2006-03-06 21:19:15 得分 0
应该不会有什么错吧
Top
8 楼wangtiecheng(不知不为过,不学就是错!)回复于 2006-03-06 21:19:25 得分 80
insert into B
select A.*
from A left join B on A.id=B.id
where B.id is nullTop
9 楼huailairen(流浪猫--很想养只猫,带着它到处流浪。)回复于 2006-03-07 04:31:34 得分 0
mysql> insert into B select * from A where id not in (select id from B)
-> ;
Query OK, 1 row affected (0.03 sec)
Records: 1 Duplicates: 0 Warnings: 0Top
10 楼my49cn()回复于 2006-03-07 17:10:38 得分 0
不知道什么原因,这么多方法中只有wangtiecheng(cappuccino) 的是有用的Top




