mysql - How to join two tables without duplicates -


i have income table looks this:

date              income       --------------------------- 09/05/13          56000     09/05/13          66600 09/05/13          50000 

and expense table looks this:

date              expense  ---------------------------- 09/05/13          68800 

i want write query output looks this:

date              income             expense  --------------------------------------------- 09/05/13          56000              68800 09/05/13          66600 09/05/13          50000 

with each value income.income , each value expense.expense appearing once. (if simple join, each 1 appear 3 times, since income.date , expense.date have duplicate values.)

if try without unique id's, full concept wrong. add unique id's table , necessary coding.

if have table structure below can write query simple equi join. income_tbl:

date              income  id     --------------------------- 09/05/13          56000   1  09/05/13          66600   2 09/05/13          50000   3 

expense_tbl:

date              expense  id ---------------------------- 09/05/13          68800    1 09/05/13                   2 09/05/13                   3 

(or) try @brian hoover's query work.

 select income.date_col, income.income, expense.expense (         select i.date_col, i.income, @currow := @currow + 1 row_number         income_tbl         join (select @currow := 0) r      ) income join (         select e.date_col, e.expense, @curexpenserow := @curexpenserow + 1 row_number         expense_tbl e         join (select @curexpenserow := 0) r      ) expense on income.row_number = expense.row_number;       

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -