Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
CREATE TABLE songs ( id int primary key, song_title varchar(64) ); INSERT INTO songs VALUES (1, 'Battle Sirens'), (2, 'Internet Friends'), (3, 'Satisfy'); CREATE TABLE artists ( id int primary key, artist_name varchar(64) ); INSERT INTO artists VALUES (1, 'Knife Party'), (2, 'Tom Morello'), (3, 'Nero'); CREATE TABLE song_artists ( song_id int references songs(id), artist_id int references artists(id), primary key (song_id, artist_id) ); INSERT INTO song_artists VALUES (1, 1), (1, 2), (2, 2), (3, 3); SELECT song_title, GROUP_CONCAT(artist_name) AS artists FROM songs JOIN song_artists ON song_artists.song_id = songs.id JOIN artists ON artists.id = song_artists.artist_id GROUP BY songs.id, song_title;

Stuck with a problem? Got Error? Ask AI support!

Copy Clear