SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
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 ChatGPT!
Copy Clear