SELECT pr.id as process_id,
lo.update_time as start_date,
REPLACE( sc.message, 'ip.ip.ip.ip', lo.variables ) as message,
sc.code
FROM logs AS lo
LEFT JOIN processes AS pr ON lo.process_id = pr.id
LEFT JOIN status_codes AS sc ON lo.status_code_id = sc.code
ORDER BY lo.id DESC
LIMIT 14
该查询的问题在于,它返回的是process_id作为所有NULL值,即使那是该表的自动递增主键,而没有任何NULL值。
最佳答案
使用SELECT lo.process_id
而不是SELECT pr.id as process_id
pr.id
是NULL
的行是processes pr
表中不存在任何记录的行。
之所以保留这些是因为您使用的是LEFT OUTER JOIN
而不是INNER JOIN
关于sql - MySQL:将主键返回为null,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4383578/