I am facing problem in query result in which if i use order by on resultset returned after group by , the grouping order is disturbed .
select a.location_id,a.feed_date
from p_article_table
inner join m_misc_details l on a.location_id = l.misc_detail_id
and misc_master_id=2
and a.location_id in (1,2,4,5,6,7,8)
and convert(varchar(11),a.feed_date,108)<'09:01:00'
group by a.location_id,a.feed_date
order by a.feed_date
What should I do ?
The result after GROUP BY on location_id gives
1
1
1
1
5
7
7
7
8
But after I use ORDER BY on feed_date , the result gets disturbed
1
1
5
7
1
8
1
..
The grouping operation is not affected by order by. The order that the grouped records are returned withoout an order by is arbitrary.
Did you want this: