Use a database transaction to isolate the queries.