sql - Microsoft Access - Joining Tables w/ different number of rows -
i'm trying make microsoft access query of 2 tables have similar columns, except 1 table has budget numbers , other has spent 2 tables have different number of rows, , since differences between 2 tables whether information budget or spent, in query (with inner join) duplicates rows of table less rows because still matches table more rows. think illustration easier explain
budgettable:
bcol1 | bcol2 | bcol3 | bcol4 | budget bill | m | employed | single | $45 mary | f | employed | married | $48 steve | m | unemployed | divorced | $38 grace | f | employed | divorced | $48 frank | m | employed | single | $50 bill | m | employed | single | $10 mary | f | employed | married | $8 grace | f | unemployed | married | $20
actualtable:
acol1 | acol2 | acol3 | acol4 | actual bill | m | employed | single | $28 mary | f | employed | married | $32 steve | m | unemployed | divorced | $21 frank | m | employed | single | $33 grace | f | unemployed | married | $13 grace | f | employed | divorced | $29
when make joins, join except last column (since there's no 1 column absolutely distinguishing feature)
but, since there 2 entries bill , mary in budget table, in query, doubles bill , mary rows in actual table comes out to
bcol1 | bcol2 | bcol3 | bcol4 | budget | acol1 | acol2 | acol3 | acol4 | actual bill | m | employed | single | $45 | bill | m | employed | single | $28 mary | f | employed | married | $48 | mary | f | employed | married | $32 steve | m | unemployed | divorced | $38 | steve | m | unemployed | divorced | $21 grace | f | employed | divorced | $48 | grace | f | employed | divorced | $29 frank | m | employed | single | $50 | frank | m | employed | single | $33 bill | m | employed | single | $10 | bill | m | employed | single | $28 mary | f | employed | married | $8 | mary | f | employed | married | $32 grace | f | unemployed | married | $20 | grace | f | unemployed | married | $13
and i'd want be:
bcol1 | bcol2 | bcol3 | bcol4 | budget | acol1 | acol2 | acol3 | acol4 | actual bill | m | employed | single | $45 | bill | m | employed | single | $28 mary | f | employed | married | $48 | mary | f | employed | married | $32 steve | m | unemployed | divorced | $38 | steve | m | unemployed | divorced | $21 grace | f | employed | divorced | $48 | grace | f | employed | divorced | $29 frank | m | employed | single | $50 | frank | m | employed | single | $33 bill | m | employed | single | $10 | mary | f | employed | married | $8 | grace | f | unemployed | married | $20 | grace | f | unemployed | married | $13
is there way in access?
why "bill-m-employed-single" in table twice? first bill, $45 budget, different bill 1 $10 budget?
if, looking @ data, human being can't tell 2 bills apart, access query won't either.
what need make each bill has unique identifier. in fact, unique identifiers. each table should have id field , join on id fields, instead of joining on each individual field.
edit: based on comments, , revelation same bill, 2 different budgets, need linking between budget-actual pairs. each job, has budget , actual, should have form of identifier, really. if ask bill how spent on job, surely response be: "which one?"
Comments
Post a Comment