straatlang
Technical User
I want to create query from three Tables Marketprices, security and currency ?
Marketprices
SECURITY PRICEDAT PRICE
ABC 12/12/02 10
ABC 13/12/02 11
ABC 14/12/02 10
DEF 15/12/02 20
GHJ 13/12/02 21
Securities
SECURITY NAME
ABC ABC Company
DEF DEF Company
GHI GHI Company
JKL JKL Company
MNO MNO Company
Currency
SECURITY CURR
ABC EUR
DEF USD
GHI USD
JKL USD
STU USD
ZZZ EUR
The result should be the last know price and pricedate on every security but i also want to see every security and the name of the company and currency when available in the report including the ones without a date and price field.
Expected result
SECURITY DATE PRICE CURR
ABC 14/12/02 10 EUR
DEF 15/12/02 20 USD
GHI 16/12/02 25 USD
JKL --/--/-- -- USD
MNO --/--/-- -- --
STU --/--/-- -- USD
ZZZ --/--/-- -- EUR
The SQL i have so far (thanks to swampBoogie) is:
select mp.security, mp.pricedate, mp.price, s.name from marketprices mp inner join secnames s on mp.security = s.security where pricedate =(select max(pricedate) from marketprices where security = mp.security)
Marketprices
SECURITY PRICEDAT PRICE
ABC 12/12/02 10
ABC 13/12/02 11
ABC 14/12/02 10
DEF 15/12/02 20
GHJ 13/12/02 21
Securities
SECURITY NAME
ABC ABC Company
DEF DEF Company
GHI GHI Company
JKL JKL Company
MNO MNO Company
Currency
SECURITY CURR
ABC EUR
DEF USD
GHI USD
JKL USD
STU USD
ZZZ EUR
The result should be the last know price and pricedate on every security but i also want to see every security and the name of the company and currency when available in the report including the ones without a date and price field.
Expected result
SECURITY DATE PRICE CURR
ABC 14/12/02 10 EUR
DEF 15/12/02 20 USD
GHI 16/12/02 25 USD
JKL --/--/-- -- USD
MNO --/--/-- -- --
STU --/--/-- -- USD
ZZZ --/--/-- -- EUR
The SQL i have so far (thanks to swampBoogie) is:
select mp.security, mp.pricedate, mp.price, s.name from marketprices mp inner join secnames s on mp.security = s.security where pricedate =(select max(pricedate) from marketprices where security = mp.security)