SQL intermediate Class - Number of Books | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

SQL intermediate Class - Number of Books

can anyone help me SELECT Authors.name, COALESCE(COUNT(Books.name), 0)AS books FROM Books RIGHT JOIN Authors ON Authors.id = Books.author_id GROUP BY Authors.id, Authors.name ORDER BY books DESC

29th Feb 2024, 4:58 PM
Bruna Yukimy Hada
Bruna Yukimy Hada - avatar
7 Answers
+ 2
SELECT Authors.name, COALESCE(COUNT(Books.name), 0) AS books FROM Authors LEFT JOIN Books ON Authors.id = Books.author_id GROUP BY Authors.id, Authors.name ORDER BY books DESC;
29th Feb 2024, 7:48 PM
Kelvin Kaloki Muema
Kelvin Kaloki Muema - avatar
+ 1
Tibor Santa So if try this, it will work? SELECT Authors.name, COALESCE(COUNT(Books.name), 0)AS books FROM Books RIGHT JOIN Authors ON Authors.id = Books.author_id GROUP BY Authors.name ORDER BY books DESC
29th Feb 2024, 8:59 PM
Bruna Yukimy Hada
Bruna Yukimy Hada - avatar
0
I try this and didnt work Kelvin Kaloki Muema
29th Feb 2024, 7:56 PM
Bruna Yukimy Hada
Bruna Yukimy Hada - avatar
0
Your select clause must contain all the fields which are listed in the group by clause.
29th Feb 2024, 8:26 PM
Tibor Santa
Tibor Santa - avatar
0
Bruna Yukimy Hada why don't you try? It looks syntactically correct, but I don't know if this answers the specific task.
1st Mar 2024, 6:19 AM
Tibor Santa
Tibor Santa - avatar
0
It works tks guys
2nd Mar 2024, 1:33 PM
Bruna Yukimy Hada
Bruna Yukimy Hada - avatar