TRUNK-4025: Fixing query issue with MySQL where you cannot update a table and select from the same table in a subquery