bug fixed by adding the group by clause