I'm writing a simple report that needs to show individuals and the number of times that each individual has been designated the author and/or owner of a document.
The two tables in the query (simplified) are: Person, with columns personID (PK) and personName; Document with columns docID (PK), authorID and ownerID.
Each report line needs to show one line per person, with the ID, name, count of authorID and count of ownerID (showing the number of times he/she was designated the author and/or owner of one or more documents).
For example:
ID ... Name ..........Author ... Owner
1 .... John Smith .... 0 ......... 3
2 .... Mary Smith .... 0 ......... 0
3 .... Peter Smith ... 1 ......... 2
I need to create a query to retrieve one row per person, then count the number of matches for Person.personID against Document.authorID and Document.ownerID.
Pseudo code might be:
SELECT p.personID, p.personName, COUNT(d.authorID) FROM Person p, Document d WHERE d.authorID = p.authorID, COUNT(d.ownerID) FROM Person p, Document d WHERE d.ownerID = p.ownerID ?
Thank you.
The two tables in the query (simplified) are: Person, with columns personID (PK) and personName; Document with columns docID (PK), authorID and ownerID.
Each report line needs to show one line per person, with the ID, name, count of authorID and count of ownerID (showing the number of times he/she was designated the author and/or owner of one or more documents).
For example:
ID ... Name ..........Author ... Owner
1 .... John Smith .... 0 ......... 3
2 .... Mary Smith .... 0 ......... 0
3 .... Peter Smith ... 1 ......... 2
I need to create a query to retrieve one row per person, then count the number of matches for Person.personID against Document.authorID and Document.ownerID.
Pseudo code might be:
SELECT p.personID, p.personName, COUNT(d.authorID) FROM Person p, Document d WHERE d.authorID = p.authorID, COUNT(d.ownerID) FROM Person p, Document d WHERE d.ownerID = p.ownerID ?
Thank you.