One way it is not working is that the where
clause is turning the first left join
into an inner join
. So, you would not be getting all rows from the query that you expect. In fact, you might not be getting any of them.
You can fix this by moving the condition into the on
clause:
SELECT ao.id AS a_id, e.id AS e_id, e.name AS evidence_name,
u.x_account_username AS username, 'evidence_edit' AS type
FROM x_ambition_owner ao
LEFT JOIN x_evidence e
ON ao.id = e.ambition_id
AND e.updated BETWEEN '2014-03-19 10:16:00' AND '2014-03-19 11:16:00'
LEFT JOIN x_user u
ON ao.profile_id = u.id;
EDIT (by OP):
This is the query I will be using:
SELECT e.id, e.name, u.x_account_username AS username, a.ambition_id
FROM x_evidence e
LEFT JOIN x_ambition_owner a
ON e.ambition_id = a.ambition_id
LEFT JOIN x_user u
ON a.profile_id = u.id
WHERE e.updated BETWEEN '2014-03-19 10:00:00' AND '2014-03-19 11:16:00'