left jion 中可以使用form 的表,而left join 中的子查询不可以使用from的主表,但是我们可以将要关联的那个字段提取出来再关联,
正确:
LEFT JOIN (
SELECT aur.create_time,appa.auditing_code FROM credit_app.auth_record aur,credit_app.auditing_info appa WHERE aur.auditing_info_id = appa.id
AND aur.state = 1 AND aur.type = 4
) ar on ar.auditing_code = a.auditingCode
错误
LEFT JOIN (
SELECT aur.create_time FROM credit_app.auth_record aur,credit_app.auditing_info appa WHERE aur.auditing_info_id = (
SELECT appa.id FROM credit_app.auditing_info appa WHERE appa.auditing_code = a.auditingCode AND appa.user_id = a.userId
)
AND aur.state = 1 AND aur.type = 4
) ar
而且出现在select中的子查询不一定会比left join中快,都是运行在内存中,要保证select子句中的where条件有索引,left 中on有索引即可