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 |
|
Ken Blum
Constraint Violating Yak Guru
383 Posts |
Posted - 2005-07-08 : 11:31:09
|
| OK, I feel a little dumb posting this since I've done it alot but I just have a severe brain cramp which could be due to being on vacation last week and going back on vacation in 2 hours. Anyway, here is the data...Washer BOF_Date Weight1 7/1/05 5001 6/30/05 10002 7/1/05 15002 6/30/05 10003 7/1/05 8003 6/30/05 1000How do I get the latest record based on the BOF_Date for each washer?1 7/1/05 5002 7/1/05 15003 7/1/05 800TIA |
|
|
mwjdavidson
Aged Yak Warrior
735 Posts |
Posted - 2005-07-08 : 12:27:19
|
| [code]SELECT mt.Washer, mt.BOF_Date, mt.WeightFROM dbo.MyTable AS mt JOIN ( SELECT mt.Washer, MAX(mt.BOF_Date) AS BOF_Date FROM dbo.MyTable AS mt GROUP BY mt.Washer ) AS latest ON mt.Washer = latest.Washer AND mt.BOF_Date = latest.BOF_Date[/code]Mark |
 |
|
|
Ken Blum
Constraint Violating Yak Guru
383 Posts |
Posted - 2005-07-08 : 12:35:17
|
| Thanks Mark! I'm now off to kill some more brain cells! |
 |
|
|
mwjdavidson
Aged Yak Warrior
735 Posts |
Posted - 2005-07-09 : 12:34:05
|
| No problemMark |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-07-11 : 01:12:20
|
Try this alsoselect Distinct washer,(select max(BOF_Date) from yourTable where Washer=T.Washergroup by Washer ),Weight from yourTable t MadhivananFailing to plan is Planning to fail |
 |
|
|
Ken Blum
Constraint Violating Yak Guru
383 Posts |
Posted - 2005-07-18 : 15:30:18
|
| Madhivanan: That result set returned all 6 rows with a date of 7/1...1 2005-07-01 00:00:00.000 5001 2005-07-01 00:00:00.000 10002 2005-07-01 00:00:00.000 10002 2005-07-01 00:00:00.000 15003 2005-07-01 00:00:00.000 8003 2005-07-01 00:00:00.000 1000 |
 |
|
|
|
|
|