多表数据 create table dep( id int primary key auto_increment, name varchar(16), work varchar(16) ); create table emp( id int primary key auto_increment, name varchar(16), salary float, dep_id int ); insert into dep values(1, '市场部', '销售'), (2, '教学部', '授课'
背景 一次处理数据的过程中,需要将表A(源表)的数据更新到表B(目标表)中 前提 两张表一定要有关联字段 使用关联字段联查两张表时,两张表关系必须满足条件:目标表和源表的表间关系一定是多对一或者一对一 使用 基本SQL如下 update tableA A set A.val = (select val from tableB B where A.idd = B.idd); 扩展 如上SQL中的tableB可以替换成任意一个子查询,典型的是源表和目标表是同一张表,SQL可以扩展如下 update
Sql Server(sybase): 1.复制表结构: 新建表student2,并且结构同表syn_xj_student一致.Sql语句如下: 2.复制表数据,并排除俩表中相同的数据: insert into syn_xj_student2 select * from syn_xj_student where f_id not in (select f_id from syn_xj_student2) mysql: 1.复制表结构: create table topic like bbs_to