I have a question about count in subquery in mysql database. Suppose I have a book
table that has a author_id
and an author
table with id
and name
. I want to get author list with number of books for each author. So I use this query:
SELECT a.id as id, a.name as name,
(SELECT COUNT(*) FROM book b WHERE b.author_id = a.id) as count
From author a
This works without any problem. But I want to know, Is this solution is best and optimized solution for such examples? If not, Is there any better workaround for these problems?
Thank you for your attention.