So two questions really:
SELECT CurrencyRateID, Rate, Markup
FROM currency_rate
WHERE CurrencyID = (SELECT CurrencyID FROM currency WHERE BaseCurr = 1) **A** AND
DateTime = (SELECT MAX(DateTime)
FROM currency_rate
WHERE CurrencyID = **B**)
- Why does this query give me an
Error Code: 1054. Unknown column ‘CurrercyID’ in ‘field list’ - How can I use the result of the first SELECT Statement A in B
Hopefully your
currency_ratetable has a unique identifier column.If it does, you can merge queries A and B into a single query in the WHERE clause…
If not, you may just have to repeat yourself…
Note: Even though the code repeats itself, it’s likely that MySQL will notice the repeition and only perform the query once.
EDIT:
I just noticed that you could simplify the first option to just use the sub-query…