I have 4 tables that is recording a value (pressure) every 30 seconds (t_stamp). I would like to join the pressures from each table into one single one. I have tried using the union statement, but it seems to join everything into one single column, instead of multiple ones. I am new when it comes to MySQL and would appreciate some help. Thanks!
Try joining them on the t_stamp instead of union.
This is how I had it, can you walk me through what you would do?
I usually don't join on a t_stamp. Also, I don't know how much time difference you have in the time values of each table. Either use date_format
to trim off the milliseconds or use an interval like below.
select
t1.value, t2.value, t3.value, t4.value, t1.t_stamp
from table1 t1
join table2 t2 on t2.t_stamp between t1.t_stamp - INTERVAL 1 SECOND and t1.t_stamp + INTERVAL 1 SECOND
join table3 t3 on t3.t_stamp between t1.t_stamp - INTERVAL 1 SECOND and t1.t_stamp + INTERVAL 1 SECOND
join table4 t4 on t4.t_stamp between t1.t_stamp - INTERVAL 1 SECOND and t1.t_stamp + INTERVAL 1 SECOND
where
date(t1.t_stamp) = curdate()
Yes, I'd only join on the t_stamp if they follow the same pattern in each table. Otherwise it's... ugly ?