Extension talk:RecentActivity

From Organic Design wiki
Revision as of 22:58, 15 March 2009 by Nad (talk | contribs)

Difficulty with last n created articles query

Lets say we have the following revision table:

 id |  page
----+----------
 1  |  Fred
 2  |  Sam
 3  |  Bob
 4  |  Bob
 5  |  Fred
 6  |  Harry
 7  |  Sam
 8  |  Mary
 9  |  Mary
10  |  Bob

Now if we just wanted the last pages that were edited we'd say:

SELECT DISTINCT page FROM revision ORDER BY id DESC

But we want the last articles created not just edited, so we need a list of the first revision of each article. Here's the ssame table with the first revision of each article marked

 id |  page
----+----------
 1  |  Fred  *
 2  |  Sam   *
 3  |  Bob   *
 4  |  Bob
 5  |  Fred
 6  |  Harry *
 7  |  Sam
 8  |  Mary  *
 9  |  Mary
10  |  Bob

And those need to be listed with a limit and descending order as follows (say linit=3):

 id |  page
----+----------
 8  |  Mary
 6  |  Harry
 3  |  Bob

What is a query to do that?