Q:

short sql challenge with multiple next row on a resultset with group by and having count

I’m coding a wiki and want to show the changes on a users inputs from other users.
Let’s say a table called Input is used as an input log, simplified to table (columns):
Input (in_id, to_id, text, us_id)
in_id is the primary key of the table Input
to_id is the primary key of the table Topic
text is some text
us_id is the primary key of the table User
The following example…
+ - - - - - + - - - - -+ - - - - -+ - - - - -+
|  in_id    |  to_id   |  text    |  us_id   |      
+ - - - - - + - - - - -+ - - - - -+ - - - - -+
|     1     |    12    |   foo    |     1    |  
|     3     |    13    |   bar    |     1    |      
|     4     |    34    |   blub   |     5    |      
|     5     |    12    |   fo     |     5    |      
|     6     |    12    |   f      |     1    |      
|     7     |    13    |   b      |     6    |      
|     8     |    13    |   ba     |     1    |      
|     9     |    13    |   bar    |     7    |      
+ - - - - - + - - - - -+ - - - - -+ - - - - -+

… should lead to the following result for the user with us_id = 1 
+ - - - - - + - - - - -+ - - - - -+ - - - - -+
|  in_id    |  to_id   |  text    |  us_id   |      
+ - - - - - + - - - - -+ - - - - -+ - - - - -+
|     5     |    12    |   fo     |     5    |      
|     7     |    13    |   b      |     6    |
|     9     |    13    |   bar    |     7    |      
+ - - - - - + - - - - -+ - - - - -+ - - - - -+

My query idea:
I`m looking for every next row in the (resultset, that shows all to_id’s with multiple  to_id's  with at least one  us_id = 1,) where us_id != 1
Various sql statements didn’t work, because I didn’t manage to handle the next row of the resultset.
SQL Statements for a single next row... 
SELECT MIN(in_id) FROM Input WHERE in_id > (in_id out of the resultset)

...and selection of to_id’s that exist more than once...
GROUP BY in_id HAVING COUNT(in_id)>1

...are not the problem.
How should it be done?

A:

Assuming the in_id sequence is incementing and "next row" means in_id is higher then "previous row", the following query yields the result:
select input.*
from 
    (select min(in_id) as idmin, to_id  
            from input 
            where us_id=1 group by to_id
    ) mintable, 
    input 
where 
   (input.to_id = mintable.to_id and input.in_id > mintable.idmin) 
   and us_id <> 1;

The inner table will select the pages where the user started editing, the second query will select all subsequent changes to this page.

