I have two tables for storing exchange rates in my system. the first one agent_rate is as follows.
ID Currency Rate
=======================
3 GBP 0.65
4 EUR 0.70
5 JPY 57.4
the second table exchange_rate is as follows.
ID Currency Rate
=======================
1 USD 1
2 ZMK 200
3 GBP 0.5
4 EUR 0.75
5 JPY 60.4
6 CHF 0.9
I want to select all the rows in the first table agent_rate and then add all the missing values of ID from the exchange_rate table. I wanted to use a union statement with distinct on a single column but I failed to. My current solution as follows (visual studio)
- select from agent_rate table and fill rate datatable
- set unique field i.e. ID in rate datatable
- select and fill from exchange_rate table into a temp datatable
- move records from temp datatable to rate datatable and ignore errors
the resulting table is(should be) as follows:
ID Currency Rate
=======================
1 USD 1
2 ZMK 200
3 GBP 0.65
4 EUR 0.70
5 JPY 57.4
6 CHF 0.9
Is there a better way to do this in Sql?