Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
From tblAidaLoucode - NameAC - AidaDD - LouEE - CFrom table tblTransactionTransID - code - amount-----------------------------------------------1 - AC - 10502 - AC - 20003 - DD - 114 - EE - 31235 - FF - 44446 - AC - 54567 - DD - 53458 - AC - 66569 - FF - 543510 - DD - 4214I want to display the amount field of the maximumTransID based on their code.How?ex Result...TransID - code - amount-----------------------------------------------8 - AC - 665610 - DD - 42144 - EE - 3123The shorter the querry the better...Want Philippines to become 1st World COuntry? Go for World War 3...
nr
SQLTeam MVY
12543 Posts
Posted - 2004-10-27 : 21:33:05
select *from tblTransaction twhere t.TransID = (select max(t2.TransID) from tblTransaction t2 where t2.code = t.code)==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy.
jonasalbert20
Constraint Violating Yak Guru
300 Posts
Posted - 2004-10-27 : 22:12:23
Thnx NR your the saviour... Want Philippines to become 1st World COuntry? Go for World War 3...
jonasalbert20
Constraint Violating Yak Guru
300 Posts
Posted - 2004-10-27 : 22:17:31
But... i just want to display the record of it available on tblAidaLou...Want Philippines to become 1st World COuntry? Go for World War 3...
jen
Master Smack Fu Yak Hacker
4110 Posts
Posted - 2004-10-27 : 22:48:33
select t.transid,t.code,max(t.amount)from tbltransaction tjoin tblaidalou aon t.code=a.codegroup by t.transid,t.code--------------------keeping it simple...
jonasalbert20
Constraint Violating Yak Guru
300 Posts
Posted - 2004-10-28 : 02:00:52
tnx for the response jen but i don't want to get the maximum of amount.Instead the amount of the maximum of TransID by code.Want Philippines to become 1st World COuntry? Go for World War 3...
jen
Master Smack Fu Yak Hacker
4110 Posts
Posted - 2004-10-28 : 02:05:30
the group by will give you that...or did it? --------------------keeping it simple...
AndyB13
Aged Yak Warrior
583 Posts
Posted - 2004-10-28 : 02:21:08
Does this give you what you wantSELECT TransId, T.Code, Amount FROM tblTransaction T INNER JOIN tblAidaLou AL ON T.Code = AL.CodeWHERE TransId IN (SELECT MAX(TransId) FROM tblTransaction GROUP BY Code)Andy