mysql - Joining and printing search results of a column with multiple values in a cell -


i have 3 databases, details follows.

i wish print columns in books_db database plus each book's genre @ same time.

a book can fall multiple genres, gave unique id each genre.
genre_id 1 - thriller , genre_id 2 - adventure etc.

--- books_db -----------     id          (int ai)     book_title  (varchar)     author      (varchar)   --- genre_link_db ------     id_books    (int)     genre_id    (int)   --- genre_db -----------     genre_id    (int)     genre       (varchar)    

so far, i've managed code sql statement. works, works 1st search result group concat() concatenate genres , not print new line next search result.

for example below, if try '%' , supposed show results, shows 1 result genres correctly printed.

select *, group_concat(t2.genre separator ', ') genre_result  (select * books_db book_title '%') t1  join (select id_books, genre genre_link_db inner join genre_db on genre_link_db.genre_id = genre_db.genre_id ) t2    on t1.id = t2.id_books; 

i believe missing group by-statement.

i rewrite joining-part of query. don't think subselects necessary here.

something have done:

select *, group_concat(t2.genre separator ', ') genre_result  books_db t1  join genre_link_db on genre_link_db.id_books = t1.id join genre_db t2 on genre_link_db.genre_id = t2.genre_id books_db.book_title '%' group t1.id; 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -