[英]better join for query performance
I need to select some date from multiple table in oracle. 我需要从oracle中的多个表中选择一些日期。 I have 2 tables, Table A and Table B which should be joined eachother. 我有2个表, 表A和表B应该相互连接。 Let me describe it in table. 让我在表中描述它。
Table A 表A
A_id x_id y_id z_id price ....
Table B 表B
B_id xyz_id myValue
NOT : x_id, y_id and z_id keeps same value with (Table B).xyz_id NOT:x_id,y_id和z_id与(表B)保持相同的值。
my query should return 我的查询应该返回
A_id, x_id, y_id, z_id, myValue for x_id, myValue for y_id, myValue for z_id
I manage that query like 我像这样管理查询
select
A_id,
(select myValue as valueForX_id from TableB where xyz_id = x_id)
(select myValue as valueForY_id from TableB where xyz_id = y_id)..,
from TableA;
but I don't know this will give best performance. 但我不知道这会带来最佳性能。 I ask for your advice. 我征求您的意见。 Thanks. 谢谢。
This should get the values using joins. 这应该使用联接获取值。 I think you will find this performs much faster for large datasets. 我认为您会发现,对于大型数据集,此方法的执行速度更快。
select a.A_id, a.x_id, a.y_id, a.z_id, x.myValue as x_value,yb.myValue as y_value, z.myValue as z_value
from TableA a
join TableB x on x.xyz_id = a.x_id
join TableB y on y.xyz_id = a.y_id
join TableB z on z.xyz_id = a.z_id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.