Hi I usually hunt the net and sleep on things until I find the answer but the following seemingly simple problem is completely evading me.
I have 2 tables,
TBL_Incidents
IncidentID
IncidentDate
IncidentReportedBy
IncidentDescription
and TBL_Comments
CommentID
CommentFromUser
Comment
There are multiple comments per incident.
I’d like to get all information from TBL_Incidents where any of the incident’s comments come from a particular user.
All the joins I’ve tried duplicate the incidents, including the left join that I was sure would have worked, e.g.
IncidentID | IncidentDate (+ all other TBL_Incident fields) | CommentID
4 | ... | 2
4 | ... | 3
4 | ... | 5
9 | ... | 12
9 | ... | 13
It’s like I want to use a group by on the Incident ID, but then it won’t give me the rest of the info from TBL_Incidents because they’re not in the group by clause.
a) does anyone have any idea what I’m babbling on about?
b) does anyone know whether it’s possible?
Many thanks.
I don’t see where Incidents and Comments are related. Is there an IncidentID in TBL_Comments? If so, then you would join on IncidentID and filter on CommentFromUser like so:
If there is no IncidentID in TBL_Comments then there is not enough information available to link them together…
Minor reading comprehension fail edit:
Assuming you’ve got the ID and you’re just combatting duplicates, slap a DISTINCT on there: