I am using datatables with a modified ssp.class.php to allow for joins and other custom features. In the example below I only want to return results from computers
for the first x rows sorted by their id. Because of this, I list computers
with my conditions first then LEFT JOIN users
followed by logs
(the information I am after).
It works great, BUT because of the left joins I have empty results. For instance, while my result set only contains logs
from the correct computers
... if logs
has no rows for a particular user/computer combination I have a row with empty log
data, but with user/computer data which serves me no purpose.
Is my only option to include a WHERE condition to prevent null values in the logs
join... WHERE logs.user_id != ''
or is there some other logic I can do in the select that I am missing?
SELECT (*see note)
FROM
( SELECT account_id, computer_id, computer_name
FROM computers
ORDER BY computer_id ASC LIMIT 0, ".$_SESSION['user']['licenses']."
) as c
LEFT JOIN users
on users.computer_id = c.computer_id
LEFT JOIN logs
on logs.user_id = users.user_id