I am not sure how to accomplish what I need. Perhaps a kind soul can push me in the right direction.
I have three tables, Users, DocType and Docs. In the DocType table there are multiple entries for allowed document types, the descriptions and other pertinent data. In the Docs table, there are all manner of documents. In the User table are the users.
The DocType and Docs tables are relational. DocType.ID = Docs.tID
The Users and Docs tables are relational. Users.ID = Docs.uID
Every user is allowed to have exactly one document of each type. Therefore if there are 10 document types in the DocType table, there may be as many as 10 matching documents in the Docs table.
What I need is a single record for each user returning a boolean for each document type, whether or not there is a matching record in the Docs table.
For example, there are 5 document types defined in the DocType table (types 1 - 5), so the DocType table has 5 rows. In the Docs table, there are 23 rows, and in the User table there are 10 rows. Given that each user may have only one of each DocType, there could be a maximum of 50 rows in the Docs table, but there are 23, meaning that on the average each user is missing one document.
Now the challenge is to return a table of all the users (10 rows) with a boolean value for each of the rows in DocType (as columns) based on whether there is a value in the Docs table that matches both the DocType and User.
however, the "as columns" part is something that should best be done in your application layer
obtaining the boolean results is straightforward
SELECT u.id AS user_id
, dt.id AS doctype_id
, CASE WHEN d.uid IS NULL
ELSE 'yup' END AS boolean
FROM users AS u
JOIN doctypes AS dt
JOIN docs AS d
ON d.uid = u.id
AND d.tid = dt.id