Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
workindan
Starting Member
21 Posts |
Posted - 2011-10-26 : 13:18:26
|
| I'm trying to join two tables and get the latest row on the second table without getting every row associated with a row on the first table. This is in Sybase, if that makes any difference.SELECT fName,lName,Address,doctor_fname,doctor_lname, doctor_dateaddedFROM persons join doctors on persons.doctorID = doctors.DoctorIDResults:Joe Bob 1234 Lane Emmit Smith 9/4/2011Joe Bob 1234 Lane George George 8/20/2011Joe Bob 1234 Lane Carol Carol 3/2/2011Joe Bob 1234 Lane Dude Dude as doctor info changes overtime, I get all the doctor records. I could do a subquery with a max function, but that takes a really long time. Is there a smarter/faster way to do this? |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-27 : 03:02:12
|
quote: Originally posted by workindan I'm trying to join two tables and get the latest row on the second table without getting every row associated with a row on the first table. This is in Sybase, if that makes any difference.SELECT fName,lName,Address,doctor_fname,doctor_lname, doctor_dateaddedFROM persons join doctors on persons.doctorID = doctors.DoctorIDResults:Joe Bob 1234 Lane Emmit Smith 9/4/2011Joe Bob 1234 Lane George George 8/20/2011Joe Bob 1234 Lane Carol Carol 3/2/2011Joe Bob 1234 Lane Dude Dude as doctor info changes overtime, I get all the doctor records. I could do a subquery with a max function, but that takes a really long time. Is there a smarter/faster way to do this?
why not take one record for each doctor and join to it?. You need to determine on what basis you want to retrieve single doctor record. is it first,last or random one------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|
|
|
|