有两张表table1与table2内容如下:
table1表
________________________
ClassId TableName
1 x
2 x1
2 x5
3 t2
3 y1
________________________ table2表
________________________
ClassId TableName
1 t
2 x1
3 ta
4 y1
2 ta
________________________
问:如果将存在table2不存在table1的记录,插入到table1表中?如果我想要的结果是:
_______________________
classid tablename
1 t
3 ta
4 y1
2 ta
_______________________
并且插入table1中,使table1变成:
classid tablename
1 t
1 x
2 x1
3 t2
3 ta
3 y1
3 y2
4 y1
该怎么做?
table1表
________________________
ClassId TableName
1 x
2 x1
2 x5
3 t2
3 y1
________________________ table2表
________________________
ClassId TableName
1 t
2 x1
3 ta
4 y1
2 ta
________________________
问:如果将存在table2不存在table1的记录,插入到table1表中?如果我想要的结果是:
_______________________
classid tablename
1 t
3 ta
4 y1
2 ta
_______________________
并且插入table1中,使table1变成:
classid tablename
1 t
1 x
2 x1
3 t2
3 ta
3 y1
3 y2
4 y1
该怎么做?
解决方案 »
- c#动态添加access数据库数据到treeview
- sql值的显示问题
- 如何筛选数据,关键是要效率,大家进来帮忙啊
- sql一个基础问题
- 谁能给提供点关于 ODBC 读取数据库的资料??
- 又一个查询问题,请教各位大哥
- SQL Server从SQL验证方式转到Window验证方式如何作?
- 怎么才能把日期给update进去。
- 请问如何在一台服务器的数据库上的存储过程调用另一台服务器的数据库上的数据??急救!!!!!!!!
- 关于SQL2000中的Raiserror错误处理,谁有经验?
- 请问: 网管数据库怎样在客户的计算机安装比较快捷方便?
- 在SQL2000中如何用SELECT 语句来查询列中数据含有"_"及"%"号内容的数据。
重复发帖了吧
insert into table1(classid,tablename)
select a.classid ,a.tablename
from table2 a left join table1 b
on a.classid=b.classid
and a.tablename=b.tablename
where b.classid is null
服务器: 消息 207,级别 16,状态 3,行 1
列名 'tablename' 无效。
select classid,tablename from table2
where not exists
(select 1 from table1 where table1.classid = table2.classid and table1.tablename=table2.tablename)
确定列名tablename是不是正确