What is the correct way to use LEFT JOINS, GROUP BY, and ORDER BY together?

Your syntax is incorrect – where clause will be before group by

SELECT tbl_headlines.id, count(tbl_weekly_builds.id) as related_count 
    FROM tbl_headlines 
    LEFT JOIN tbl_weekly_builds ON tbl_headlines.id = tbl_weekly_builds.headline 
    WHERE tbl_headlines.deleted is null 
    GROUP BY tbl_headlines.id 
    ORDER BY LOWER(tbl_headlines.label) asc 
    LIMIT 0, 100;

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top