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.
Hi I need to make a select from 2 tables whit this layout always with the newest datetime exchange currency.The local cuurency is Mexican PesosTable 1 Currencies example:CurrencyID Key Description1 USD USA Dollar2 EUR European Euro3 Yen Japan YenTabla 2 is Day exchange CurrencyCurrencyID Equivalent DateTime1 12.50 2010-08-07 08:00:001 12.55 2010-08-07 08:10:001 12.49 2010-08-07 08:20:001 12.60 2010-08-07 08:30:001 12.51 2010-08-07 08:40:001 12.52 2010-08-07 08:50:001 12.48 2010-08-07 09:00:001 12.61 2010-08-07 09:10:00 <-- the newest xchange for USD2 16.87 2010-08-07 08:00:002 16.90 2010-08-07 08:10:002 16.88 2010-08-07 08:20:002 16.85 2010-08-07 08:30:002 16.87 2010-08-07 08:40:002 16.92 2010-08-07 08:50:002 16.80 2010-08-07 09:00:002 16.95 2010-08-07 09:10:00 <-- the newest xchange for Euro3 6.73 2010-08-07 08:00:003 6.70 2010-08-07 08:10:003 6.78 2010-08-07 08:20:003 6.75 2010-08-07 08:30:003 6.77 2010-08-07 08:40:003 6.72 2010-08-07 08:50:003 6.70 2010-08-07 09:00:003 6.75 2010-08-07 09:10:00 <-- the newest xchange for EuroThe select query I need is always the newest exchange currency for each currency in table 1, something like thisCurrencyID Key Description Equivalent DateTime1 USD USA Dollar 12.61 2010-08-07 09:10:002 EUR European Euro 16.95 2010-08-07 09:10:003 Yen Japan Yen 6.75 2010-08-07 09:10:00How can i do the select?Plese help me Jose Roberto Chavez
slimt_slimt
Aged Yak Warrior
746 Posts
Posted - 2010-08-07 : 13:21:24
If i'm reading table schema right, try this:
selectCurrencyID,Key,Description,Equvivalent,max(DateTime)from Table_1group by CurrencyID, Description, Equvivalent