Home Forums SQL Server 2008 SQL Server 2008 - General how to avoid duplictae records of column in a table in a select query in this proc? RE: how to avoid duplictae records of column in a table in a select query in this proc?

  • You can do it as follows:

    --Query for your requirement

    Select boardid, companyid, companyname, countrycode, city From

    (

    Select b.boardid, b.companyid, a.companyname, a.countrycode, a.city ,ROW_NUMBER() Over (Partition By a.CompanyName Order by b.createddate DESC) As rn

    From @companytable as a

    JOIN @boardtable as b On a.companyid = b.companyid

    ) As p

    Where rn = 1

    Order by boardid DESC

    The query gets you the data that you want. But, you did not mention the logic which was behind your requirement. The query may need some change if your logic is different from what i used.

    From next time please post the logic behind the requirement as well so that it becomes easier to deduce a solution.

    Vinu Vijayan

    For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden[/url] 😉