Având trei tabele – book(bookID, bookTitle), author(authorID, last_name, first_name), aut_book(authorID, bookID), redarea autorilor si cartilor aferente, poate fi redată ca atare.
|
1 2 3 4 5 6 7 |
SELECT DISTINCT GROUP_CONCAT(DISTINCT a.first_name, ' ', a.last_name SEPARATOR ', ') AS authors , b.bookTitle, b.bookID, a.authorID FROM book AS b LEFT JOIN aut_book AS ab ON ab.bookID = b.bookID LEFT JOIN author AS a ON a.authorID = ab.authorID GROUP BY b.bookID HAVING a.authorID IS NOT NULL |
Sursa: StackOverflow.com