Joe Developer is working on a new application for a book publisher. Authors can publish zero or more books. Books can have zero or more authors.
Joe wrote a query to get a total count of all authors, and a total count of all books. Joe read on the Internet that the DISTINCT keyword is good to use in these scenarios.
SELECT DISTINCT
COUNT(Authors.Id) AS TotalAuthors,
COUNT(Books.Id) As TotalBooks
FROM
Authors
FULL JOIN AuthorsBooks AB ON Authors.Id = AB.AuthorID
FULL JOIN Books ON AB.BookID = Books.Id
The problem is - the numbers seem too high. What's wrong? Is it easy to fix?