I have two table as follows :-
table1 table2
date time amount date time amount
20120101 1000 101 20120104 1000 10
20120101 1100 100 20120104 1100 11
20120104 1000 101 20120105 1000 11
20120104 1100 105 20120105 1100 8
I want to join these two tables to get the output as follows :
date time table1-amt table2-amt
20120101 1000 101 NULL
20120101 1100 100 NULL
20120104 1000 101 10
20120104 1100 105 11
20120105 1000 NULL 11
20120105 1100 NULL 8
What is the sql query to get this output? I am using mysql database.
I tried following query:
select table1.date,table1.time,table1.close , table2.close
from table1,
table2
where table1.date=table2.date
and table1.time=table2.time;
it gave me output as
date time amount amount
20120104 1000 101 10
20120104 1100 105 11
People are directing me towards left outer join , full outer join I tried following two queries which did nt solve my purpose .
select * from table1 left join table2 on table1.date=table2.date ;
select * from table1 left join table2 on table1.date=table2.date union select * from table1 right join table2 on table1.date=table2.date;