作业帮 > 综合 > 作业

SQL 中left join连接多张表

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/29 20:08:01
SQL 中left join连接多张表
因为业务原因查询多张表,如此:
select
from table A
left join table A1 on .
left join table A2 on .
left join table A3 on .
left join table A4 on .
left join table A5 on .
left join table A6 on .
left join table A7 on .
left join table A8 on .
left join table A9 on .
left join table A10 on .
left join table A11 on .
left join table A12 on .
where
.
这样的一个语句,确实是有十几张表需要连接(数据库表结构就是这样.)
这种写法查询效率怎么样,还有没有更好的写法
这样写效率肯定不高.如果数据大,很有可能把数据库跑死.
遇到这种情况,建议使用临时表,写成存储过程.把要查询的数据分字段插入临时表,然后再查询临时表.