I did previously ask a question about this, but must admit was biased against SQL based solutions and now I can’t find the question, so I’ll try again, phrase it carefully and be much more open to any solutions provided.
I have two tables:
tblCurrent
Ref | CustomerID | ... .. .. . . |
X001
X002
X003
tblHistorical
Ref | ... .. .. . . | Missing | Matched
X001 | ... .. .. . . | TRUE | FALSE
X001 | ... .. .. . . | FALSE | FALSE
X002 | ... .. .. . . | TRUE | TRUE
X002 | ... .. .. . . | TRUE | FALSE
X003 | ... .. .. . . | FALSE | FALSE
X003 | ... .. .. . . | TRUE | TRUE
Ref is unique in tblCurrent, but not in Historical.
How can I construct a view, that is based on tblCurrent that results in three additional columns that count the number of records in tblHistorical that:
-
match the Ref AND Missing is TRUE
-
match the Ref AND Missing is False
-
match the Ref AND Matched is True
Note that I will need to add additional columns that count the number of records in tblHistorical based on similar criteria.
I think you need to use
LEFT JOINon this since it is possible that sometimerefmay not exist ontblHistoricaltable.