Tidy up MySQL queries.