I have this php query;
$sql = "SELECT *
FROM store AS s
LEFT JOIN setting as set ON (s.store_id = set.store_id)";
$sql .= " WHERE (set.key = 'config_template' OR set.key IS NULL)";
$sql .= " ORDER BY url";
$query = $this->db->query($sql);
What i would like to do is return all rows where key is equal to “config_template”. But if there are no keys that match “config_template”, I still want to return that row except the column key would be empty.
I thought about using NOT IN or NOT EXIST but I am not sure how to use these in this circumstance?
Moving the condition for the key into the JOIN condition should do the trick: