Say I have two tables, author and book. Each author can have multiple books, identified by the authorId column of the book table which is linked to the id field of author table.
I want to fetch all the books with a certain category Id, and for each book I want to get the author's name and photo url to be displayed next to the book title.
So I do a query like this:
SELECT author.name, author.photoUrl, book.title
FROM author, book
WHERE book.categoryId = '3' AND author.id = book.authorId
The problem is, what if an author has multiple books in the category? (E.g a fiction writer writes multiple fiction books). In that case, will the author's info be fetched separately for each row, hence fetching duplicate info, or is there any way such as using DISTINCT
so an author's info is only fetched once?