SQL SELECT: "Give me all documents where all of the documents procedures are 'work in progress'"

Posted by prestonmarshall on Stack Overflow See other posts from Stack Overflow or by prestonmarshall
Published on 2010-04-20T06:33:09Z Indexed on 2010/04/20 6:43 UTC
Read the original article Hit count: 426

Filed under:
|
|

This one really has me stumped. I have a documents table which hold info about the documents, and a procedures table, which is kind of like a revisions table for each document. What I need to do is write a select statement which gives me all of the documents where all of the procedures have the status "work_in_progress". Here's an example

procedures table:

document_id | status
1           | 'wip' 
1           | 'wip'
1           | 'wip'
1           | 'approved'
2           | 'wip'
2           | 'wip'
2           | 'wip'

Here, I would want my query to only return document id 2, because all of its statuses are work_in_progress. I DO NOT want document_id 1 since one of its statuses is 'approved'. I believe this is relational division I want, but I'm not sure where to start. This is MySQL 5.0 FYI.

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql