formatted the sql query