I have two tables, samples
sample_id status member_id
1 pass 2
2 pending 2
3 pending 2
4 pending 1
and votes
vote_id sample_id member_id
1 1 1
2 1 1
3 1 5
4 2 2
Both samples.sample_id and votes.vote_id are autoincrementing and samples.member_id and votes.member_id should be joined where samples.member_id=someUserId.
I would like to return a result set of samples.sample_id where
- samples.status is pending
- The
samples.member_iddid not submit a sample - The
votes.member_idhas not voted for a sample
example 1
For example, if the member_id is 1, the result set should be
2
3
Since samples.status where samples.sample_id = 1 is not pending, and samples.member_id submitted samples.sample_id 4.
example 2
If the member_id is 2, the result set should be
4
Since samples.member_id has submitted samples.sample_id 1-3.
example 3
If the member_id is 3, the result set should be
2
3
4
Since samples.status where samples.sample_id = 1 is not pending
EDIT
Of the three conditions that have to be met, I can meet the first one with the following
SELECT * FROM samples
LEFT OUTER JOIN votes on samples.sample_id = votes.vote_id
WHERE samples.status='pending'
But I am struggling meeting the other two conditions
1 Answer