Fix sql queries.