SQL queries fixed