Anda mungkin ingin mempertimbangkan untuk menggunakan GROUP_CONCAT()
seperti ini:
SELECT
b.id,
b.title,
GROUP_CONCAT(CONCAT(a.fname,' ' , a.lname)) AS author_names,
GROUP_CONCAT(a.id) as author_ids
FROM books b
LEFT JOIN author_book ab
ON b.id = ab.book_id
LEFT JOIN authors a
ON ab.author_id = a.id
WHERE b.id = '406'
GROUP BY b.id
Itu akan memberi Anda output seperti:
406 | The world of the wheel of time | Robert Jordan,Teresa Patterson | 2,3