I have this 3 queries result
z_id | data | c_email_i
--------+------------+-----------
276050 | 2012-03-30 | 1
319536 | 2012-07-23 | 1
190033 | 2010-01-18 | 1
271987 | 2011-11-02 | 1
319554 | 2012-08-21 | 1
370881 | 2013-06-18 | 1
z_id | data | c_call_o
--------+------------+----------
169456 | 2009-09-07 | 1
148231 | 2009-09-25 | 2
240949 | 2010-10-25 | 2
119116 | 2009-01-09 | 2
219206 | 2010-09-29 | 1
243121 | 2010-11-02 | 1
z_id | data | c_call_i
--------+------------+----------
169456 | 2009-09-07 | 1
148231 | 2009-09-25 | 2
240949 | 2010-10-25 | 2
119116 | 2009-01-09 | 2
219206 | 2010-09-29 | 1
243121 | 2010-11-02 | 1
And I want to join it to result like this
z_id | data | c_email_i | c_call_o | c_call_i
------+------------------+-----------+----------+----------
119116| 2009-01-09 | 0 | 2 | 2
169456| 2009-09-07 | 0 | 1 | 1
276050| 2012-03-30 | 1 | 0 | 0
...........
I tried to use UNION, but there was to many columns with (0 as fake_column) and i didnt like that. (but it was really fast)
On other side when I use left join (on dates and z_id tables) there is Query that takes like 40minutes with 800k results.