Fixed the sql query