带有或条件的左连接会降低查询性能,因此可以替代左连接或条件
select tableb.columnA, tableb.columnB,tablec.id,tabled.id,tablee.id
from tableA tableA
LEFT JOIN tableb tableb ON ((tableb.columnA = tableA.id)
OR (tableb.columnB = tableA.id))
LEFT JOIN tablec tablec ON tablec.Id = tableb.columnA
LEFT JOIN tabled tabled ON tabled.id = tableb.columnB
LEFT JOIN tablee tablee ON tablee.Id= tableb .id
答案 0 :(得分:0)
我将从在单独的tableb
的{{1}}上再次加入columnb
开始。
在其他联接上,您可以像join
一样使用ISNULL
函数。
根据您的需求和数据,可以使用tablec.Id = ISNULL(tableba.columnA, tablebb.columnA)
/ UNION
或UNION ALL
从COALESCE
的适当实例中获取数据。
并确保tableb
中的两列都被索引覆盖。