I want to output an element inside an array that match the index during a prior match in SQL/BigQuery
The objective is to match the MATCH_ID to either MATCH_HOME or MATCH_AWAY, then output the date (as MATCH_DATE) from MATCH_HOME_DATE (if it matches an element in MATCH_HOME) or MATCH_AWAY_DATE (if it matches an element in MATCH_AWAY). The matching date should have the same index with where it matched in MATCH_HOME or MATCH_DATE
For example, I have these 5 fields (and their data types).
| MATCH_ID (STRING) | MATCH_HOME (STRING) | MATCH_AWAY (STRING) | MATCH_HOME_DATE (ARRAY(STRING)) | MATCH_AWAY_DATE (ARRAY(STRING)) |
|---|---|---|---|---|
| 19.56V.25 | 19.56V.25, 19.52X.26 | 19.48W.27, 19.35R.28 | [2021-10-30,2021-10-31] | [2021-11-05,2021-11-06] |
| 19.24C.17 | 19.25S.19, 19.15M.17 | 19.21A.19, 19.24C.17 | [2021-11-27,2021-11-28] | [2021-12-11,2021-12-12] |
Output MATCH_DATE should be:
|MATCH_DATE |
|:---- |
| 2021-10-30 |
| 2021-12-12 |
Since line 1 matches with 1st element of MATCH_HOME and line 2 matches with 2nd element of MATCH_AWAY.