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 things ( id int primary key auto_increment, id_thing int, data varchar(64) ); CREATE TABLE notes ( id int primary key auto_increment, id_thing int, note varchar(64), foreign key (id_thing) references things(id) ); INSERT INTO things (id_thing, data) VALUES (1, 'Thing 1'), (2, 'Other thing'); INSERT INTO notes (id_thing, note) VALUES (1, 'Thing 1 note'), (1, 'Thing 1 one more note'), (2, 'Important note about Other thing'); SELECT things.id_thing, things.data, GROUP_CONCAT(note SEPARATOR '\n') notes FROM things LEFT JOIN notes USING(id_thing) GROUP BY things.id_thing, things.data ;

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

Copy Clear