how can I join two tables and make the second optional?
SELECT t1.title,SUM(t2.seconds) AS seconds
FROM operation t1
LEFT JOIN workhours t2 ON t1.id = t2.pid AND t1.status='0'
ORDER BY t1.tstamp DESC
This query shows only one result but there is a second one withour any worktime on it. How can I make sure that the data from t1 will always be displayed even when there is nothing in t2?
You need to add
GROUP BY t1.title:In general, if title is not unique, you should group by unique key.