I'm currently working on SQL analysis. There are 3 tables, the first one contains name_id; timestamp; description. the 2nd and 3rd tables have only name_id; timestamp.
What I'd like to achieve is a table like Goal table below:
- The first 3 columns of that table would be essentially table_1 ordered;
- The column
other_timestamp
should be populated by takingname_id; timestamp
from table_1 and searching through table_2 and table_3 byname_id
and finding the next following chronologicaltimestamp
asociated with thename_id
from table_1(could be in either one of the tables); - Column
source_of_other_timestamp
should be populated by showing from which table did theother_timestamp
came from (either table_2 or table_3)
table_1
name_id | timestamp | description
name_1 | timestamp_1 | description_1
name_2 | timestamp_2 | description_3
...
name_n | timestamp_n | description_n
table_2 and table_3
name_id | other_timestamp
name_1 | other_timestamp_1
name_2 | other_timestamp_2
...
name_n | other_timestamp_n
Goal table
name_id | timestamp | description | other_timestamp | source_of_other_timestamp
name_1 | timestamp_1 | description_1 | other_timestamp_1 | table_2
name_2 | timestamp_2 | description_2 | other_timestamp_2 | table_3
...
name_n | timestamp_n | description_n | other_timestamp_n | table_2
Thank you!