I have a table named table1, with one column named col1, which takes value in range 1-9.
table1
col1
1
9
7
2
4
6
1
9
3
5
Now I want to add another column which maps values in col1 to another value given in a map. 1 -> A, 2 -> B, 3 -> C, 4 -> D, 5 -> E, 6 -> F, 7 -> G, 8 -> H, 9 -> I
I want results to look like below.
col1 col2
1 A
9 I
7 G
2 B
4 D
6 F
1 A
9 I
3 C
5 E
My approach is to create a new table with mapping and then do a inner join.
CREATE TABLE map (
col1 int,
col2 varchar
);
INSERT INTO map
(col1, col2)
VALUES
(1,'A'),(2,'B'),(3,'C'),(4,'D'),(5,'E'),(6,'F'),(7,'G'),(8,'H'),(9,'I');
SELECT table1.col1, map.col2
FROM table1 INNER JOIN map ON table1.col1 = map.col1
Is this efficient approach, are there better methods than this?