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 ««12

Easy (I hope) join question Expand / Collapse
Author
Message
Posted Friday, August 2, 2013 10:02 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Today @ 5:36 AM
Points: 34, Visits: 146
Good point... For the sample data that is definitely smarter. In my actual data I have about 6 fields that are like 'address' in that there could be multiple distinct values and I only want to pick one - I suppose I could put min() for each one but that would probably be more expensive, right?
Post #1480488
Posted Friday, August 2, 2013 10:28 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 3:35 PM
Points: 13,253, Visits: 12,087
taigovinda (8/2/2013)
Good point... For the sample data that is definitely smarter. In my actual data I have about 6 fields that are like 'address' in that there could be multiple distinct values and I only want to pick one - I suppose I could put min() for each one but that would probably be more expensive, right?


Actually MIN would be less expensive than using Row_Number. Since you say you only want to pick one, you have to either make a decision about the rules for which one or get a random one.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1480513
Posted Friday, August 2, 2013 11:22 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Today @ 5:36 AM
Points: 34, Visits: 146
Thanks!
Post #1480537
Posted Friday, August 2, 2013 11:03 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 6:46 PM
Points: 36,944, Visits: 31,446
taigovinda (8/2/2013)
Good point... For the sample data that is definitely smarter. In my actual data I have about 6 fields that are like 'address' in that there could be multiple distinct values and I only want to pick one - I suppose I could put min() for each one but that would probably be more expensive, right?


Careful... if you put MIN on each column, you could end up having Detroit in California.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1480667
Posted Saturday, August 3, 2013 8:28 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Today @ 5:36 AM
Points: 34, Visits: 146
Thanks for realizing that I needed that caution!

(I had to test the code that Lowell provided in order to understand that the same address would not be returned for both rows. I see, hopefully correctly, that it is the group by which ensures Mike doesn't get Tai's address but would not prevent mismatches within one person's distinct addresses...)
Post #1480693
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse