mysql将多个表内容添加到一个表中

mysql将多个表内容添加到一个表中,第1张

1、先添加完,删除所有重复记录,再insert一次

insert into A select * from B

insert into A select * from C

insert into A select * from D

2、删除重复的记录只保留一行

delete from A where name in (select id from t1 group by id having count(id) >1)and rowid not in (select min(rowid) from t1 group by id having

count(*)>1)

3、记录一下这些重复的记录,

mysql -uroot -p123456 -Ddb01 -e 'select b.id from t1 b group by id having count(b.id) >1' | tail -n +2 >repeat.txt

删除全部重复的记录

delete from A where name in (select name from t1 group by name having count(name) >1)

再次插入多删的重复记录

#!/bin/sh

for id1 in `cat repeat.txt`do

mysql -uroot -p123456 -Ddb01 -e "insert into A select * from B where id='${id1}'"

done

给你几个情况

1.如果是累加name是这样的

update

b

set

name=name+a.name

from

a

where

a.url=b.http

2.直接插入

insert

b(name)

select

name

from

a

join

b

on

a.url=b.http

3.替换原来的name

update

b

set

name=a.name

from

a

where

a.url=b.http

insert into table1 values(数据)

insert into table2 values(数据)

insert into table3 values(数据)

一起提交就是多个表同时添加


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11447902.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存