表A 有22个字段与表B的id关联,然后我希望得到表B的unitprice字段,现在我使用的是
select A.id,A.name,A.a01,b1.unitprice as a01_unitprice,...,A.a22,b22.unitprice as a22_unitprice from A
left join B as b1 on A.a01 = b1.id
left join B as b2 on A.a02 = b2.id
...
left join B as b22 on A.a22 = b22.id
where A.id = ${id}
表A有15000条数据
表B有3000条
现在的查询耗时10s+
有什么更快的方法吗?
A表
id | name | a01 | a02 | a03 | ... | a22 |
---|---|---|---|---|---|---|
1 | hello | 1255 | 24 | 1 | ... | 51 |
B表
id | name | unitprice |
---|---|---|
1 | aa | 34 |
2 | 7wdr | 69 |
... | ... | ... |
你知道你这么查相当于有多少行么?
15000^20次
select * from A, B where A.id = {id} and (A.a01 = B.id or A.a02 = B.id ...)