I executed the following query, containing columns SearchText, SearchURL, LastModifiedDateTime, Country

```
 select Top 30 * from SearchHistory  order by LastModifiedDateTime desc

```

There are a lot of duplicate records in this. I need distinct(SearchURL) records order by latest LastModifiedDatetime.

I tried this query:

```
 SELECT Top 30 *  FROM   (SELECT *,  Row_number()
                                             OVER(
                                             PARTITION BY SearchURL
                                             ORDER BY LastModifieddateTime desc) AS RN
                                             FROM   SearchHistory where searchtext is not null )A
                                        WHERE  RN = 1 

```

but I get different set of results altogether (very old records are at top). 

I need the **top 30 distinct(searchurl) records order by LastModifiedDatetime desc**