【发布时间】:2019-10-09 22:17:56
【问题描述】:
我有 2 个由 cronjobs 自动填充的表(一个事件表和一个包含事件地址的位置表。由于两个提要不同,有时事件通过 location_id1 链接到位置,但有时使用 location_id2,就像这样:
locations table:
id imported_id1 imported_id2 address
1 NULL 20 xx
2 10 NULL xx
...
events table:
id location_id1 location_id2 some_data
1 NULL 20 xx
2 10 NULL xx
...
要选择事件并获取链接到位置的正确地址,我尝试了这样的JOIN,但OR 使查询运行速度慢得多:
SELECT * FROM events
JOIN locations ON
events.location_id1 = locations.limported_id1
OR events.location_id2 = locations.limported_id2;
谁有更好的方法来查询这个?
【问题讨论】: