我有以下查询:
select distinct places.*
from places
left join place_address on place_address.place_id = places.id
left join addresses on place_address.address_id = addresses.id
left join cities on addresses.city_id = cities.id
where
(places.description like '%Boston%' or cities.name = 'Boston')
and places.status = 1
order by places.name
它返回正确的结果,但是运行非常慢。如果我从“左连接”切换为“连接”,则运行速度很快,但是如果没有关联的地址,则不会返回“ places.description”匹配的结果。有没有一种方法可以构造此结构以获得我想要的结果并使其快速运行?
places Table
- id
- name
- description
- status
place_address Table
- place_id
- address_id
addresses Table
- id
- city_id
cities Table
- id
- name
我已经看到有关左联接的类似问题,它们建议将WHERE子句的部分移至“ ON”条件,但是对于最左边和最右边的表,这似乎不适用于“ OR”条件