现在有个很棘手的问题,小弟是新手,对mysql不是很熟悉
目前是这个样子
有10个表
表名为demo_0,demo_1....demo_9,
这十个表的结构完全相同,但每个表都有200多万行,
我需要将这十个表union 为一个临时表,然后再跟另一个test表的字段关联小弟写的sql如下:
select * from (select * from demo_0 union all
select * from demo_1 union all
select * from demo_2 union all
select * from demo_3 union all
select * from demo_4 union all
select * from demo_5 union all
select * from demo_6 union all
select * from demo_7 union all
select * from demo_8 union all
select * from demo_9
) as demo
left join test on test.id = demo.c_id
where .....结果是直接跑不动,请各位大侠指点
目前是这个样子
有10个表
表名为demo_0,demo_1....demo_9,
这十个表的结构完全相同,但每个表都有200多万行,
我需要将这十个表union 为一个临时表,然后再跟另一个test表的字段关联小弟写的sql如下:
select * from (select * from demo_0 union all
select * from demo_1 union all
select * from demo_2 union all
select * from demo_3 union all
select * from demo_4 union all
select * from demo_5 union all
select * from demo_6 union all
select * from demo_7 union all
select * from demo_8 union all
select * from demo_9
) as demo
left join test on test.id = demo.c_id
where .....结果是直接跑不动,请各位大侠指点
比如:select * from (select * from demo_0 union all
select * from demo_1
left join test on test.id = demo.c_id
where .....union all select * from demo_2
left join test on test.id = demo.c_id
where .....
...
) as demo最好把整个数据操作流程贴出来,这样能更好的优化。