111

Saturday, February 8, 2020

SQL: 3 tables (book, author, book_author)?

answers1:Yes, you need to use MySQL's GROUP_CONCAT function.
answers2:As you're using mySQL, you should look at the GROUP_CONCAT
function. It can be found
at:http://dev.mysql.com/doc/refman/5.0/en/group-by-fu...I don't have
access to a mySQL database right at this moment that I can check this
works, but the following should do what you're after:SELECT
book.[book_id], book.[title], GROUP_CONCAT(author.[name] SEPARATOR ',
') FROM (book INNER JOIN book_author ON
book_author.[book_id] = book.[book_id]) INNER JOIN
author.[author_id] ON author.[author_id] =
book_author.[author_id] WHERE book.[book_id] = '1'Obviously change the
where statement to whatever you want/need.Hope this helps!....Show
more

No comments:

Post a Comment