SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table accounts( `id` bigint(20) UNSIGNED NOT NULL auto_increment, data varchar(36), `created_at` timestamp NULL DEFAULT NULL, `updated_at` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`) ); insert into accounts(data, created_at, updated_at) values('Test 1', now(), now()); insert into accounts(data, created_at, updated_at) values('Test 2', now(), now()); insert into accounts(data, created_at, updated_at) values('Test 3', now(), now()); create table account_locks( account_id bigint(20) UNSIGNED NOT NULL, pid varchar(36), `created_at` timestamp NULL DEFAULT NULL, `updated_at` timestamp NULL DEFAULT NULL ); insert into account_locks(account_id, pid) select id, UUID() from accounts left join account_locks on account_id = accounts.id group by id having count(account_locks.account_id) < 3 limit 1 for update; select * from account_locks;

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear