I have a table like this with many records. for example:HREFTopic PopularTopic LastModifiedTime ------------------------------------------------------------------------------ //twitter.com/search?q=%23Happy #Happy St. Patrick's Day 2015-03-17 19:57:18.000 //twitter.com/search?q=%23Happy #Happy St. Patrick's Day 2015-03-17 18:57:17.000 //twitter.com/search?q=%23HappyV #Happy Valentines Day 2015-03-17 17:57:15.000
This is my stored proceduredeclare @abc nvarchar(max) declare @SearchKey nvarchar(max) select @SearchKey ='Happy' select top 10 @abc = COALESCE(@abc + '','') + '<li>' + '<a class="z" href="' +'../q.aspx?q=' + @SearchKey + '">' + (PopularTopic) + '</a></li>' + char(10) + char(13) from PopularTrends where HREFTopic like '%'+ @SearchKey +'%' order by LastModifiedTime desc select @abc
and the output is (@abc) =<li><a class="z" href="../q.aspx?q=Happy">Happy St. Patrick's Day</a></li> <li><a class="z" href="../q.aspx?q=HappyV">Happy Valentines Day </a></li> <li><a class="z" href="../q.aspx?q=Happy">Happy St. Patrick's Day</a></li> <li><a class="z" href="../q.aspx?q=Happy">Happy St. Patrick's Day</a></li> <li><a class="z" href="../q.aspx?q=Happy">Happy St. Patrick's Day</a></li> <li><a class="z" href="../q.aspx?q=Happy">Happy St. Patrick's Day</a></li> <li><a class="z" href="../q.aspx?q=Happy">Happy St. Patrick's Day</a></li>
but I need only distinct(PopularTopic) order by LastModifiedTime and I expect the result to be :<li><a class="z" href="../q.aspx?q=Happy">Happy St. Patrick's Day</a></li> <li><a class="z" href="../q.aspx?q=HappyV">Happy Valentines Day </a></li>
I am not able to get the distinct(PopularTopic), rather I get all the records. Can some one help me with getting the right query