Steinar Midtskogen <stei...@latinitas.org> wrote:
> [Igor Tandetnik]
> 
>>> timestamp|value1|value2|value3|value4|value5|value6
>>> 1328873000|1|2| |  |  |
>>> 1328873050| | |7|  |  |
>>> 1328873075| | | |10|13|16
>>> 1328873100|3|4| |  |  |
>>> 1328873150| | |8|  |  |
>>> 1328873175| | | |11|14|17
>>> 1328873200|5|6| |  |  |
>>> 1328873250| | |9|  |  |
>>> 1328873275| | | |12|15|18
>>> 
>>> But, first things first, how can I merge my tables to get the combined
>>> table with NULLs?
>> 
>> select value1, value2, null, null, null, null from tab1
>> union all
>> select null, null, value3, null, null, null from tab2
>> union all
>> select null, null, null, value4, value5, value6 from tab3;
> 
> Thanks, I didn't think in that simple terms. :) I think about listing
> all the values, so I got lost.
> 
> But what if the tables share a timestamp, then I would get, say:
> 
> 1328873300|1|2| | | |
> 1328873300| | |3| | |
> 1328873300| | | |4|5|6
> 
> How can that get collapsed into:
> 
> 1328873300|1|2|3|4|5|6

Try something like this:

select timestamp, value1, ..., value6 from
(select timestamp from tab1
 union
 select timestamp from tab2
 union
 select timestamp from tab3)
left join tab1 using (timespamp)
left join tab2 using (timespamp)
left join tab3 using (timespamp);

-- 
Igor Tandetnik

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to