A while ago, I asked for help on this SQL query. It shows snippets that belong to a parent category, using the category ID to tie them together. I tried to change it to show all categories, even when there's no snippets inside but I can't manage it.
I am sure this is not a PHP thing, as printing the result of this query does not show empty categories.
I just need help understanding this and what I need to change to make it show what I need it to.
Here's the SQL:
SELECT c.id AS cid, c.slug AS cslug, c.name AS cname, s.id AS sid, s.name AS sname
FROM categories AS c
LEFT JOIN snippets AS s ON s.category = c.id
WHERE c.live=1 AND s.live=1 AND c.company='$company' AND s.company='$company'
ORDER BY c.name, s.name
Any tips and links to good resources to learn SQL would be appreciated too. :)
Here's an example of what the query returns when run through PHP. SQL http://jsbin.com/obonal PHP Inefficient SQL Query