I am trying to get the first record the first time and then the second record with the second query. I am using those two queries but they return the same thing:

```
SELECT M.CODE,
ISNULL((SELECT TOP 1 *
FROM (
SELECT TOP 1 PRICE AS PRICE FROM MTRLINES ML WHERE ML.MTRL=M.MTRL AND FINDOC IN (SELECT FINDOC FROM FINDOC WHERE SOSOURCE=1251 AND FPRMS IN (1,2)) ORDER BY FINDOC DESC ) T
ORDER BY PRICE),0) AS B
FROM MTRL M
WHERE M.SODTYPE=51 AND M.COMPANY=1 AND M.CODE=:kod_an
ORDER BY M.CODE

```

This gets the first record then trying to execute this query to get the second record:

```
SELECT M.CODE,
ISNULL((SELECT TOP 1 *
FROM (
SELECT TOP 2 PRICE AS PRICE FROM MTRLINES ML WHERE ML.MTRL=M.MTRL AND FINDOC IN (SELECT FINDOC FROM FINDOC WHERE SOSOURCE=1251 AND FPRMS IN (1,2)) ORDER BY FINDOC DESC ) T
ORDER BY PRICE),0) AS B
FROM MTRL M
WHERE M.SODTYPE=51 AND M.COMPANY=1 AND M.CODE=:kod_an
ORDER BY M.CODE

```

But it returns the same result. I am still learning thanks!

Edit:

Just a simple illustration just to get the idea: User passes the variable `:kod_an`

I have two tables for example:

```
|MTRL|  CODE  |
---------------
| 1  | 080109 |
| 2  | 085145 |
| 3  | 084141 |

|MTRL|  PRICE  | FINDOC |
-------------------------
| 1  |  4.95   | 12345  |
| 1  |  4.50   | 23421  |
| 1  |  3.90   | 23499  |

```

So the user is searching for the code (:kod\_an) the last two prices (in our example `:kod_an=080109`). My output should be `3.90` in the first query and `4.50` in the second query. Findoc should have descending order, in order to select the first time the last one and the second time the second one from the top this time! 

To conclude my queries is showing 3.90 in both situations. I do not know why...