Ordering price when multi-currency table
I have a table, lets call it products, that includes 2 columns for price and currency. Its dealing with euros, pounds and dollars.
I want to be able to generate the logic that can sort the table on the price, but by taking into account the currency exchange rates.
So, lets say the PRODUCTS table has the following records:
If you were to simply sort ascending on Price, it would return:
But if we want to return the results ASCending, according to lowest price value first (taking exchange rate into account), it would need to return:
I do have a RATES table stored in SQL, that has this structure:
id from to rate
1 eur gbp 0.683
Which has all of the conversion rates for all possibilities stored in it.
Does anyone have any ideas of the type of SQL code that could achieve this?