MP3JOSS

GROUP_CONCAT function in SQL

GROUP_CONCAT function in SQL

Choose Download Format

Download MP3 Download MP4

Details

TitleGROUP_CONCAT function in SQL
AuthorQ Visible
Duration5:54
File FormatMP3 / 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

🎧 Just For You

🎵 Sorry Im Here For Someone Else - Benson… 🎵 Despacito - Luis Fonsi & Daddy Yankee… 🎵 Happy - Pharrell Williams 🎵 Uptown Funk - Mark Ronson Feat. Bruno Mars 🎵 Dior - Mk & Chrystal 🎵 Rolling In The Deep - Adele 🎵 A Bar Song (Tipsy) - Shaboozey 🎵 Forever Young - David Guetta, Alphaville… 🎵 Call Me Maybe - Carly Rae Jepsen 🎵 Pink Pony Club - Chappell Roan 🎵 Apt. - Ros & Bruno Mars 🎵 Wasted Love - Austria (Eurovision)