fixed the sql query