SELECT ... FOR UPDATE (MySQL)
SELECT ... FOR UPDATE (MySQL) is a SQL clause in the MySQL Specific category. Locks selected rows for update. NOWAIT: fail immediately if locked. SKIP LOCKED: skip locked rows. The syntax is SELECT ... FOR UPDATE [OF table] [NOWAIT | SKIP LOCKED];. It returns locked rows. A typical example: START TRANSACTION; SELECT * FROM inventory WHERE product_id = 100 FOR UPDATE; -- Locks the inventory row UPDATE inventory SET quantity = quantity - 1 WHERE product_id = 100; COMMIT; -- WITH SKIP LOCKED: skip rows currently locked by others SELECT * FROM jobs ORDER BY priority FOR UPDATE SKIP LOCKED LIMIT 1; -- Worker: pick next available job, skipping locked ones A close relative is AUTO_INCREMENT, which mySQL auto-generates sequential integer values for this column. Commonly used with PRIMARY KEY. A close relative is ENGINE, which specifies the MySQL storage engine. InnoDB (default) supports transactions and foreign keys. MyISAM is faster for read-heavy.