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 |
|
gotafly
Yak Posting Veteran
54 Posts |
Posted - 2005-05-05 : 13:22:26
|
| I have 2 tables. A master and detail . I wand to end up with a max bDate, and t2Val for bob. So..1 bob 5/15/2005 boattable 1t1IDt1Name1 bob2 garyTable 2t2IDt1IDbDatet2Val1 1 2/11/2005 car2 1 5/15/2005 boat3 2 3/23/2005 van4 1 1/01/2005 cart |
|
|
JimL
SQL Slinging Yak Ranger
1537 Posts |
Posted - 2005-05-05 : 14:52:26
|
| Select bdate ,t2valfrom table1 innerjoin table2 on table1.t1id = table2.t1idwhere t1name = 'bob' and bdate in (Select max(bdate) from table1 innerjoin table2 on table1.t1id = table2.t1id where t1name = 'bob' )JimUsers <> Logic |
 |
|
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2005-05-05 : 16:39:29
|
| [code]declare @t1 table(t1id int, t1name varchar(15))declare @t2 table(t2id int, t1id int, bdate datetime, t2val varchar(15))insert into @t1 select 1, 'bob' union select 2, 'gary'insert into @t2 select 1, 1, '2/11/2005', 'car' union select 2, 1, '5/15/2005', 'boat' union select 3, 2, '3/23/2005', 'van' union select 4, 1, '1/01/2005', 'cart'select top 1 t1.t1id, t1.t1name, t2.bdate, t2.t2valfrom @t1 t1 inner join @t2 t2 on t1.t1id = t2.t1idorder by 3 desc[/code] ... testing |
 |
|
|
|
|
|
|
|