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 promos ( id int, contracts_ids json ); INSERT INTO promos VALUES (1, '["11","12"]'), (3, '["11","12","13"]'); CREATE TABLE contract ( id int, name varchar(64) ); INSERT INTO contract VALUES (11, "A"),(12, "B"),(13, "C"); SELECT contracts_ids, JSON_ARRAYAGG(name) FROM promos LEFT JOIN contract ON JSON_CONTAINS(contracts_ids, CONCAT('"', contract.id, '"')) GROUP BY promos.id, contracts_ids;

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

Copy Clear