GROUP_CONCAT function in SQL

Details
Title | GROUP_CONCAT function in SQL |
Author | Q Visible |
Duration | 5:54 |
File Format | MP3 / MP4 |
Original URL | https://youtube.com/watch?v=-KyDvtH1Fvg |
Description
The GROUPCONCAT function (abbreviated from Group Concatenate) and it's equivalent is in many different database systems. It useful in merging together different records in a query result set. Especially across many to many relationships where a junction or associative table is used.
In this example we use a library database where many authors can be associated with many books and, conversely many books can be associated with many authors. If we want to list all the books and their authors using normal select queries, a book that has two authors will be represented on two different lines on the result set. We can blend or concatenate these two into one line in the same query.
Final Query:
SELECT title, GROUP_CONCAT(author_name) from t_books JOIN jnct_authors_books ON book_id=book_fk JOIN t_authors ON author_id=author_fk GROUP BY title
Follow me on twitter: https://twitter.com/qVisible