|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Friday, March 25, 2011 2:28 PM
Points: 74,
Visits: 194
|
|
Daniel Bowlin (9/22/2010) Try a CTE or temp table to get your DISTINCT then join that back to a SELECT where you query the data and constrain on the MIN or MAX of Column C
Thank you for your reply. I solved my issue as follows :
Select Distinct ColumnA, Max(ColumnB) As ColumnB, Max(ColumnC) As ColumnC From SoAndSoTable Group By ColumnA
Thanks again Daniel, and of course Thank You Luke.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 9:42 AM
Points: 2,891,
Visits: 5,858
|
|
tsmith-960032 (9/22/2010)
Daniel Bowlin (9/22/2010) Try a CTE or temp table to get your DISTINCT then join that back to a SELECT where you query the data and constrain on the MIN or MAX of Column CThank you for your reply. I solved my issue as follows : Select Distinct ColumnA, Max(ColumnB) As ColumnB, Max(ColumnC) As ColumnC From SoAndSoTable Group By ColumnA Thanks again Daniel, and of course Thank You Luke.
Sorry, for the late reply, but yes that's why I was trying to get at. When you do your grouping you need to decide which results you want from Columns b and c. The MAX() function will get you there.
Glad it worked out for you, however using the DISTINCT Keyword and a GROUP BY clause is redundant and I'm somewhat amazed that SQL doesn't throw an error here. I understand that it doesn't 'cause I just tested it, but it still seems like something strange and perhaps may cause you issues down the road. I'd remove the DISTINCT Keyword and just stick with the GROUP BY clause for clarity.
-Luke.
To help us help you read this
For better help with performance problems please read this
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Friday, April 19, 2013 12:52 AM
Points: 13,
Visits: 28
|
|
|
|
|