I'm trying to put two tables together using struct and array. My idea is for each row in table A apply Levenshtein Distance to table B.
Table A:
col1
whisky
delta
Tango
Table B
col1
Whiskey
delta force
Tango is great
Desired output:
col1 col2 col3
whisky Whiskey <lv_distance_score>
delta force <lv_distance_score>
Tango is great <lv_distance_score>
delta Whiskey <lv_distance_score>
delta force <lv_distance_score>
Tango is great <lv_distance_score>
Tango Whiskey <lv_distance_score>
delta force <lv_distance_score>
Tango is great <lv_distance_score>
For this, first I'm trying to just get de desired output of col1 and col2, but I keep getting an error
that says Scalar subquery produced more than one element
.
The query I wrote is:
WITH a AS (
SELECT col1, [STRUCT((SELECT col1 FROM table_B))] AS col2 FROM table_A
)
SELECT col1,c2 FROM a,UNNEST(a.col2) AS c2;
What I'm doing wrong here? How can I achieve what I'm looking for?