Created
November 4, 2011 08:33
-
-
Save maxp/1338922 to your computer and use it in GitHub Desktop.
forum unread topic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| create table user ( id serial, ... ); | |
| create table group ( id serial, ... ); | |
| create table topic ( | |
| id serial, | |
| group_id int foreign key group(id) | |
| ); | |
| create table lastread ( | |
| id serial, | |
| user_id int foreign key user(id), | |
| topic_id int foreign key topic(id), | |
| last_post int | |
| ); | |
| select | |
| distinct t.group_id | |
| from | |
| topic t left join lastread lr on (t.id == lr.topic_id) | |
| where | |
| (lr.topic_id is null) or | |
| (t.last_post_id > lr.post_id and lr.user_id == ?) | |
| ; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment