View Single Post
Old 02-05-2021, 05:39 AM   #11
Nicolas.Laurent
Member
Nicolas.Laurent began at the beginning.
 
Posts: 22
Karma: 10
Join Date: Jun 2016
Location: France
Device: PocketBook Touch Lux 2
Quote:
Originally Posted by chaley View Post
BTW, the reason your SQL doesn't work is that some of the subqueries return multiple rows. You only see the first one. To see all of them you need to use group_concat(), like this:
Code:
SELECT
    id,
    author_sort,
    title,
    (SELECT name FROM publishers WHERE publishers.id IN (SELECT publisher from books_publishers_link WHERE book=books.id)) publisher,
    (SELECT group_concat(format) FROM data WHERE data.book=books.id) formats,
    path,
    (SELECT group_concat(name) FROM tags WHERE tags.id IN (SELECT tag from books_tags_link WHERE book=books.id)) tags
FROM books
you are a genius (which you probably already knew)!
The query works perfectly
Thanks again for your help.
Nicolas.Laurent is offline   Reply With Quote