如何查找相同数据 在sql中 我有两个表 一个4000多数据 一个6000多条数据 这两个表内容一样 那个4000多是从6000多条数据里拿出来的 ,现在我想联合查询 这两个表不同的数据 然后提出来 放在另一个表中 。各位怎么写啊? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 insert newtableselect a.*from tab6000 a left join tab4000on a.key = b.keywhere b.key is null select * from table_a where id not in (select id from table_b) or :insert newtableselect a.*from tab6000 a where not exists (select 1from tab4000 bon a.key = b.key) 修正3楼insert newtableselect a.*from tab6000 a where not exists (select 1from tab4000 bwhere a.key = b.key) select A.* from A where A.ID not in (select B.ID From B)A:6000多条数据表B:4000多条数据表ID:为主键这样就可以提取出所有的不同数据插入到另一个表中了 --A表是6000多条数据表--B表是4000多条数据表--C表是新生成的表insert into Cselect * from A t1 where not exists(select 1 from B where id=t1.id) insert into newtableselect*from Aexceptselect*from B注:1、事先建好newtable表结构 2、A为大表,B为小表。 假如4000条数据的表是AA 6000的是BB那么 SELECT B.* FROM AA A,BB B WHERE B.关键字段 not in (select 关键字段 from AA) insert into Cselect * from A t1 where not exists(select 1 from B where id=t1.id) insert newtableselect a.*from tab6000 a where not exists (select 1from tab4000 bon a.key = b.key) sqlserver2005 的安装目录问题 linux+mysql+php VS windows+sqls+asp 关于数据类型的转化FLOAT-VARCHAT 日期比较的存储过程 测试SQL 进来讨论一个分页查询(Alibaba) 高分求助!!SQLServer里可以对日期格式的数据进行操作嘛,例如:我有一个日期20030609,我想得到11天前的日期,该怎么做呢? 求唯一的订单编号,困扰许久了 有哪几种后台程序可以链接SQL SERVER数据库? 100分求解一个SQL语句的写法,在线等候.... SQL语句合并 求教:外键与删除问题,
select a.*
from tab6000 a left join tab4000
on a.key = b.key
where b.key is null
select a.*
from tab6000 a
where not exists (
select 1
from tab4000 b
on a.key = b.key
)
select a.*
from tab6000 a
where not exists (
select 1
from tab4000 b
where a.key = b.key
)
A:6000多条数据表
B:4000多条数据表
ID:为主键
这样就可以提取出所有的不同数据插入到另一个表中了
--A表是6000多条数据表
--B表是4000多条数据表
--C表是新生成的表
insert into C
select * from A t1 where not exists(select 1 from B where id=t1.id)
select*from A
except
select*from B注:1、事先建好newtable表结构
2、A为大表,B为小表。
那么 SELECT B.* FROM AA A,BB B WHERE B.关键字段 not in (select 关键字段 from AA)
select * from A t1 where not exists(select 1 from B where id=t1.id)
select a.*
from tab6000 a
where not exists (
select 1
from tab4000 b
on a.key = b.key
)