FOR UPDATE
FOR UPDATE is a SQL clause in the SELECT Queries category. Locks selected rows for update — prevents other transactions from modifying them until COMMIT. The syntax is SELECT ... FROM table WHERE condition FOR UPDATE;. It returns locked result set. A typical example: START TRANSACTION; SELECT * FROM accounts WHERE id = 1 FOR UPDATE; -- This row is locked for update UPDATE accounts SET balance = balance - 100 WHERE id = 1; COMMIT; -- Lock released after commit A close relative is SELECT, which retrieves data from a table. The most fundamental SQL statement. A close relative is SELECT *, which selects all columns from a table. A close relative is SELECT DISTINCT, which returns only distinct (unique) values from the specified columns. More about this category: Core SELECT query clauses — SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT. Related SELECT Queries entries: SELECT, SELECT *, SELECT DISTINCT, WHERE, AND / OR / NOT, IN, BETWEEN, LIKE.