开发者

Compare and insert from multiple tables?

开发者 https://www.devze.com 2023-02-08 00:07 出处:网络
There are 4 tables table1,table2开发者_StackOverflow中文版,table3 and table4 table1 has got 60000 datas

There are 4 tables table1,table2开发者_StackOverflow中文版,table3 and table4

table1 has got 60000 datas
table2 has got 85000 datas
table3 has got 78000 datas
table4 has got 68000 datas

indexes on all tables are same but one got less than or more than each other. for example name john is stored in all 4 tables.but mathew is stored in may be two tables but not in other two and ethan may be stored in 3 tables but not may be in 4th one.

upto say first 60k all index/names are same but after that it is irregular

so how can I merge all these table into 1 table?? all four tables got 2 columns each and first one is name and second is its details


There are probably more efficient ways of doing this, but this was the first thing that came to mind.

INSERT INTO table5
SELECT DISTINCT Table5Content.* FROM (
SELECT * FROM table1
UNION ALL
SELECT * FROM table2
UNION ALL
SELECT * FROM table3
UNION ALL
SELECT * FROM table4
UNION ALL
SELECT * FROM table5
) as Table5Content
0

精彩评论

暂无评论...
验证码 换一张
取 消