Like the question says is there a better way to write this:
SELECT clients_lists.*,
COUNT(clients_lists_relationships.clientid)
FROM clients_lists
LEFT JOIN clients_lists_relationships
ON clients_lists.listid = clients_lists_relationships.listid
WHERE clients_lists.parentid = 1
GROUP BY clients_lists.listid;
Not really. The query looks fine to me. You can try to use aliases for better readability:
But it won’t really make a technical difference (not that I know).
Also make sure that both
clients_lists.listidandclients_lists_relationships.listidare of the same datatype and length and are indexed. This will definitely help your query’s performance.