Un blog afișează fiecare autor cu numărul de articole publicate și folosește LEFT JOIN ca să apară și autorii fără articole. Ce întoarce interogarea?
CREATE TEMP TABLE authors (id int, name text);
CREATE TEMP TABLE posts (author_id int, published boolean);
INSERT INTO authors VALUES (1, 'Ana'), (2, 'Dan'), (3, 'Eva');
INSERT INTO posts VALUES (1, true), (1, false), (2, false);
SELECT a.name, COUNT(p.author_id)
FROM authors a
LEFT JOIN posts p ON p.author_id = a.id
WHERE p.published = true
GROUP BY a.name
ORDER BY a.name;