SQL 中left join连接多张表因为业务原因查询多张表,如此:selectfrom table Aleft 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 o
来源:学生作业帮助网 编辑:作业帮 时间:2024/05/03 08:28:15
SQL 中left join连接多张表因为业务原因查询多张表,如此:selectfrom table Aleft 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 o
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
.
这样的一个语句,确实是有十几张表需要连接(数据库表结构就是这样.)
这种写法查询效率怎么样,还有没有更好的写法
SQL 中left join连接多张表因为业务原因查询多张表,如此:selectfrom table Aleft 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 o
这样写效率肯定不高.如果数据大,很有可能把数据库跑死.
遇到这种情况,建议使用临时表,写成存储过程.把要查询的数据分字段插入临时表,然后再查询临时表.