Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

select distinct rows Expand / Collapse
Author
Message
Posted Wednesday, July 31, 2013 2:50 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, November 4, 2013 8:13 AM
Points: 190, Visits: 367
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

Post #1479705
Posted Wednesday, July 31, 2013 3:00 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, June 27, 2014 8:03 AM
Points: 320, Visits: 1,079
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.
Post #1479708
Posted Thursday, August 1, 2013 1:00 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, January 31, 2014 2:56 AM
Points: 483, Visits: 256
SELECT TOP 1 .......

returns only one row
Post #1479803
Posted Thursday, August 1, 2013 6:57 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, October 31, 2013 3:44 AM
Points: 314, Visits: 4,128
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.
Post #1479925
Posted Thursday, August 1, 2013 7:18 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, September 9, 2014 3:27 AM
Points: 1,893, Visits: 2,329
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/
Post #1479936
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse