
SQL 中left join连接多张表
请教一下因为业务原因查询多张表,如此:selectfromtableAleftjointableA1on.....leftjointableA2on.....leftjo...
请教一下
因为业务原因查询多张表,如此:
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
.......
这样的一个语句,确实是有十几张表需要连接(数据库表结构就是这样.....)
想问一下,这种写法查询效率怎么样,还有没有更好的写法 展开
因为业务原因查询多张表,如此:
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
.......
这样的一个语句,确实是有十几张表需要连接(数据库表结构就是这样.....)
想问一下,这种写法查询效率怎么样,还有没有更好的写法 展开
2个回答
展开全部
这样写效率肯定不高。如果数据大,很有可能把数据库跑死。
遇到这种情况,建议使用临时表,写成存储过程。把要查询的数据分字段插入临时表,然后再查询临时表。
遇到这种情况,建议使用临时表,写成存储过程。把要查询的数据分字段插入临时表,然后再查询临时表。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这种写法效率肯定不高了,需要你进行拆分,也要看你写这个sql的目的是什么了。
追问
举例的话就是从A4、 A6 、 A8 、A10 、 A11 、A12 中各获得一个字段信息,然后其他的表是关联表
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询