By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE IF NOT EXISTS Transactions (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, url TEXT NOT NULL, code INTEGER NOT NULL);
✓
INSERT INTO transactions (url, code) VALUES
('https:/x.com/?a=1', '0'), ('https:/x.com/?a=2', '0'), ('https:/x.com/?a=3', '0');
✓
SELECT * FROM transactions;
id | url | code |
---|---|---|
1 | https:/x.com/?a=1 | 0 |
2 | https:/x.com/?a=2 | 0 |
3 | https:/x.com/?a=3 | 0 |
UPDATE transactions
SET code = 1
WHERE id = (SELECT MIN(id) FROM transactions WHERE code = 0)
RETURNING id;
id |
---|
1 |