select * from
(
select *,ROW_NUMBER() over (PARTITION BY f1 ORDER BY f1) as r from [Agriculture].[dbo].[cc]
) a where a.r=1
select COUNT(distinct query_id)FROM [Agriculture].[dbo].[mm]
select * from (
select ROW_NUMBER() over(partition by [Query_id] order by [Query_id]) RowNum
,[Agriculture].[dbo].[mm].*
from [Agriculture].[dbo].[mm]) as t1 where RowNum = 1