I have a select result like this:
ID | DATE
----------------
10 | 2014-07-23
7  | 2014-07-24
8  | 2014-07-24
9  | 2014-07-24
1  | 2014-07-25
2  | 2014-07-25
6  | 2014-07-25
3  | 2014-07-26
4  | 2014-07-27
5  | 2014-07-28
The result above is ordered by date. Now, I want to select the one previous row before:
2  | 2014-07-25
Which is:
1  | 2014-07-25
In case I don't know the exact ID and the conditional code must be compatible with if I want to select a previous row of:
3  | 2014-07-26
Which is:
6  | 2014-07-25
What condition should I use?
UPDATE
Tried this:
SET @rank=0;
SELECT @rank:=@rank+1 AS rank, t1.*
  FROM table t1
Then I got this:
RANK | ID | DATE
----------------
1    | 10 | 2014-07-23
2    | 7  | 2014-07-24
3    | 8  | 2014-07-24
4    | 9  | 2014-07-24
5    | 1  | 2014-07-25
6    | 2  | 2014-07-25
7    | 6  | 2014-07-25
8    | 3  | 2014-07-26
9    | 4  | 2014-07-27
10   | 5  | 2014-07-28
Then I tried this:
SET @rank=0;
SELECT @rank:=@rank+1 AS rank, t1.*
  FROM table t1
  WHERE rank < 3;
I got this error: Unknown column 'rank' in 'where clause'.
 
     
     
     
    