Reputation: 523
I have a table called BOOK_AUTHORS
. It has two columns:
book_id | author_name
Primary Key = (book_id + author_name)
This is because one book may have multiple authors.
I want to create a view from this where I can have book_id as the primary key and the author_name concatenated for multiple authors.
e.g. Book 'XYZ' has two authors namely 'ABC' and 'PQR'. so it has two rows in the current BOOK_AUTHORS
table as shown below:
book_id | author_name
|
XYZ | ABC
XYZ | PQR
After creating the view, I want to get this:
book_id | author_name
|
XYZ | ABC, PQR
How can I achieve this?
Upvotes: 0
Views: 39
Reputation: 782
You can try with
SELECT GROUP_CONCAT(author_name) WHERE book_id = 'XYZ';
Upvotes: 2