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 products ( id_product int, id_category int, position int, primary key (id_product, id_category) ); INSERT INTO products VALUES (15, 12, 10), (190, 12, 10), (191, 12, 11), (230, 12, 12), (15, 143, 12), (150, 143, 50); SELECT * FROM products; INSERT IGNORE INTO products SELECT id_product, 143 as id_category, (SELECT MAX(position) FROM products WHERE id_category = 143) + (row_number() over (order by id_product)) as position FROM products WHERE id_category = 12; SELECT * FROM products;

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

Copy Clear