change the sql query for right output