select distinct rows

  • hi

    my stored prc return value slike this

    rule date no

    abc1 03/17/2003 23

    abc1 04/15/2004 45

    abc2 04/43/2009 120

    i need to display only 1 rule on my front end.if i put distinct or group by still its not working

  • SELECT DISTINCT will only drop rows where all column values in the select statement are the same as another row. None of your sample rows matches any other, so none get dropped.

    If you use GROUP BY you should be able to get 1 row - but exactly how you do it depends on what you want

    e.g.

    SELECT [Rule], MAX([Date]) as [Date], MAX(No) as No

    FROM #Table

    GROUP BY [Rule]

    will give you one row per rule, but may not be exactly what you want.

  • SELECT TOP 1 ....... returns only one row

  • Look up the ROW_NUMBER() Function in Books Online. You can use it to distinguish the rows as you see fit then select the one you want.

    If you do choose to go that way and you need help then I would advise you supply ddl/test data.

  • please provide some more information like what output you required so that we can help you..........

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply