t1 table
+-----------+------------------+ | cookie_id | impression | +-----------+------------------+ | 123 | 6/17/15 | | 123 | 6/18/15 | | 123 | 6/18/15 | | 234 | 6/20/15 | | 234 | 6/22/15 | +-----------+------------------+ t2 table +-----------+---------+---------+---------+ | cookie_id | hp | search | book | +-----------+---------+---------+---------+ | 123 | 6/17/15 | | | | 123 | 6/18/15 | | | | 123 | | 6/18/15 | | | 123 | | | 6/19/15 | | 234 | 6/23/15 | | | | 234 | | 6/25/15 | | | 234 | | | 6/29/15 | +-----------+---------+---------+---------+ we'd join t1 , t2 expected result below t3 table :
+-----------+------------+---------+---------+---------+ | cookie_id | impression | hp | search | book | +-----------+------------+---------+---------+---------+ | 123 | 6/17/15 | | | | | 123 | 6/18/15 | | | | | 123 | 6/18/15 | | | | | 123 | | 6/17/15 | | | | 123 | | 6/18/15 | | | | 123 | | | 6/18/15 | | | 123 | | | | 6/19/15 | | 234 | 6/20/15 | | | | | 234 | 6/22/15 | | | | | 234 | | 6/23/15 | | | | 234 | | | 6/25/15 | | | 234 | | | | 6/29/15 | +-----------+------------+---------+---------+---------+
http://sqlfiddle.com/#!9/375e6/2
select cookie_id, impression, null,null, null t1 union select cookie_id, null impression, hp, search,book t2
Comments
Post a Comment