I have 2 tables with epoch values. One with multiple samples per minute such as:
| id | First_name | epoch_time |
|---|---|---|
| 1 | Paul | 1650317420 |
| 2 | Jeff | 1650317443 |
| 3 | Raul | 1650317455 |
And one with 1 sample per minute:
| id | Home | epoch_time |
|---|---|---|
| 1 | New York | 1650317432 |
What I would like to do is join on the closest timestamp between the two tables. Ideally, finding the closest values between tables 1 and 2 and then populating a field from table 1 and 2. Id like to populate the 'Home' field and keep the rest of the records from table 1 as is, such as:
| id | Name | Home | epoch_time |
|---|---|---|---|
| 1 | Paul | New York | 1650317420 |
| 2 | Jeff | New York | 1650317443 |
| 3 | Raul | New York | 1650317455 |
The problem is the actual join. The ID is not unique hence why I need to not only join on ID but also scan for the closest epoch time between the 2 tables. I cannot use correlated subqueries, since Presto doesn't support correlated subqueries.