sql - Combining Data from Two Tables into One Row -


i've read around quite bit solution problem can't seem work. seems simple problem i'm not getting result set want.

i'm working on report needs pull 2 tables , create 1 row of data each employee. file needs uploaded healthcare vendor.

here example of data

table1: employeecheckdeduction

employee id  deduction amount  check date        1234             50.00   6/30/2015        1234             50.00   7/15/2015        4567            100.00   6/30/2015        4567            100.00   7/15/2015        9876             75.00   6/30/2015        9876             75.00   7/15/2015 

table2: employercontribution

employee id  contribution amount  check date        1234                25.00   6/30/2015         1234                30.00   7/15/2015        4567                50.00   6/30/2015        4567                60.00   7/15/2015 

part of problem not every record in table1 have corresponding match in table 2. if maxed out on contributions, won't receive 1 on pay. want result set looks this:

employee id  deduction amount  contribution amount  check date        1234             50.00                25.00   6/30/2015        1234             50.00                30.00   7/15/2015         4567            100.00                50.00   6/30/2015        4567            100.00                60.00   7/15/2015        9876             75.00                 0.00   6/30/2015        9876             75.00                 0.00   7/15/2015 

no matter how try , join, it's duplicating data. i've tried using subqueries or distinct records , no matter try, it's not giving me want. can't figure out i'm doing wrong.

edit. see links below dataset results.

http://s000.tinyupload.com/index.php?file_id=01551050904538574848

http://s000.tinyupload.com/index.php?file_id=63978789937644749322

http://s000.tinyupload.com/index.php?file_id=28700836121558977952

i think part of problem in employee check deduction table there specific deduction code i'm pulling out. in employer deduction table code exists. however, whenever try , add join on 2 fields in addition employee id , check date, doesn't return results employees have deduction amount in employee check deduction table when don't have corresponding record in employer contribution table. hope helps.

select a.employee_id, a.deduction_amount, b.contribution_amount,  a.check_date  employeecheckdeduction join employercontribution b  on a.employee_id = b.employee_id  , a.check_date = b.check_date 

try renaming columns if necessary. should join on employed , checkdate.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -