I have a log table like this:

```
line    Date                    status  Type
1   26.04.2016 08:58    IN  4
2   26.04.2016 08:59    OUT 80
3   26.04.2016 09:05    REZ 7
4   26.04.2016 09:06    IN  7
5   26.04.2016 09:22    EDIT    81
6   26.04.2016 09:23    EDIT    80
7   26.04.2016 09:24    OUT 80
8   26.04.2016 09:25    OUT 80
9   26.04.2016 09:25    OUT 80

```

"date" is the key.

I want to get last type change date. In this example last type is "80" and the min date of it is 26.04.2016 09:23 (line 6).

I know the last type at this point (@lasttype = 80).
But if I run `select min(date) from table where type = @lasttype`, then I get line 2 instead of line 6.

How can I get min date of last block of "type" (line 6) **in one query**? I don't want to use several select after and after. 

I have just try this but line 6 doesn't come again:(

```
select max(date)
from
(
    select min(date) as date, type
    from MYTABLE
    where type = '80'
    group by type
) as t1

```

Is there a easy way?

Many thanks.

Edit:
Ok, I can get line 6:

```
select min(date) from MYTABLE where date > (select max(date) from MYTABLE where type <> @lasttype)

```

Any more effective code?

Many thanks for your answers...