Skip to content
SQLSimplified
BackendQuestion 39 of 52

Pessimistic Locking (FOR UPDATE)

Problem

You are building a ticketing system for a concert. You need to ensure that when two people try to buy the same seat at the exact same millisecond, only one succeeds. Your tech lead says you need to lock the row while you read it. Write a query that outputs concept with the value: "SELECT ... FOR UPDATE locks the selected rows so other transactions cannot modify them until the current transaction completes."

Database Schema

This problem acts as a scratchpad. You will write your own DDL/DML or conceptual queries, so there is no predefined schema.

Try It

Loading playground environment...

Hint

Solution