Ponieważ masz filtr dla notes
tabela w WHERE
klauzula JOIN
działa jak INNER JOIN
, przenieś go do JOIN
warunek:
SELECT
jobs.*,
MAX(notes.`timestamp`) AS complete_date
FROM jobs
LEFT JOIN notes
ON (jobs.id=notes.job_id)
AND (notes.type="complete" OR notes.type IS NULL)
WHERE (jobs.status="complete" OR jobs.status="closed")
GROUP BY jobs.id
ORDER BY complete_date ASC;
Można to również zrobić za pomocą podzapytania, więc zastosuj filtr notatek wewnątrz podzapytania:
SELECT
jobs.*,
n.complete_date
FROM jobs
LEFT JOIN
(
select job_id, MAX(`timestamp`) AS complete_date
from notes
where (type="complete" OR type IS NULL)
group by job_id
) n
ON (jobs.id=n.job_id)
WHERE (jobs.status="complete" OR jobs.status="closed")
ORDER BY complete_date ASC