I have a Maria DB and I'm trying to update a table from two other tables. Archive Table - timestamped data up to 00 UTC last night. Current - timestamped data from 00 to now. I want to copy the results from both tables to a column in a summary table.
Archive Table
time|result
1 A
2 B
3 C
4 D
5 E
Current table:
time|result
6 1
7 2
8 3
9 4
10 5
Summary Table:
time|result
1 A
2 B
3 C
4 D
5 E
6 1
7 2
8 3
9 4
10 5
I've been able to update based on a single INNER JOIN between the summary table and either the archive or Current table independently, but I haven't been able to figure out how to combine it.
Since Archive and Current are identical and don't overlap, it seems like I should UNION the archive and current and then update the summary table? I've also tried performing two LEFT OUTER JOINS and filter out the NULLS, but I'm still missing something.
Is this something I should be using a sub query on?
I'm completely new to this and only need to get past a couple of queries for a project. I'm hoping someone can help point me in the right direction.
Thanks for any advice
I'm not sure from your question whether your
Summary
table is empty or not.Assuming it's empty and you need to populate it, then
UNION ALL
will do, which doesn't strip duplicates and saves time (as opposed toUNION
which under the hood sorts records and then removes duplicates):