Skip to content

Instantly share code, notes, and snippets.

@latompa
Created June 16, 2010 01:52
Show Gist options
  • Save latompa/440013 to your computer and use it in GitHub Desktop.
Save latompa/440013 to your computer and use it in GitHub Desktop.
Videos
+------+------------------+
| id | uploaded_by_user |
+------+------------------+
| 1 | tom |
| 2 | mark |
| 3 | tom |
| 4 | mark |
| 5 | tom |
| 6 | john |
+------+------------------+
Video_ratings:
+----------+--------+---------------+
| video_id | rating | rated_by_user |
+----------+--------+---------------+
| 1 | 5 | tom |
| 1 | 4 | mark |
| 5 | 2 | mark |
+----------+--------+---------------+
The simplest query we could come up with was:
select id from videos
where not exists
(select video_id as id from video_ratings
where videos.id=video_ratings.video_id
and video_ratings.rated_by_user='mark'
)
and uploaded_by_user != 'mark'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment