Fixed SQL queries