I’d like to create an SQL statement that will tell me how many books where written by a given author.
When you know the authorid (foreign key to books table) it’s easy:
select count(*) from books where authorid = 25;
15
You can see that author with id 15 has written 15 books. Is it possible to create a statement for all the authors such that the ouput is as follows?
author_id, author_name, number_of_books
1 Michael 15
2 Robin 7
...
You could do this with a
group byclause: