Contiguous Ranges of primary keys: a more cross platform and faster approach

In last article Finding Contiguous primary keys we detailed one of many ways of finding continuous ranges in data, but the approach would only work on higher-end dbs like Oracle 11G, SQL Server 2012, and PostgreSQL 8.4+. Oracle you'd have to replace the EXCEPT I think with MINUS. It wouldn't work on lower Oracle because of use of CTEs. It wouldn't work on lower SQL Server because it uses window LEAD function which wasn't introduced into SQL Server until SQL Server 2012. Someone on reddit provided a Microsoft SQL Server implementation which we found particularly interesting because - it's a bit shorter and it's more cross-platform. You can make it work with minor tweaks on any version of PostgreSQL, MySQL, SQL Server and even MS Access. The only downside I see with this approach is that it uses correlated subqueries which tend to be slower than window functions. I was curious which one would be faster, and to my surprise, this version beats the window one we described in the prior article. It's in fact a bit embarrassing how well this one performs. This one finished in 462 ms on this dataset and the prior one we proposed took 11seconds on this dataset. Without further ado. To test with we created a table:

CREATE TABLE s(n int primary key);
INSERT INTO s(n)
SELECT n
FROM generate_series(1,100000) As n
WHERE n % 200 != 0;

For those people who don't have the luxury of generate_series function, we've packaged the table as a bunch of inserts in s table

-- SQL Server implementation (any version)
SELECT
    FirstInRange.n as start_n,
    (SELECT TOP 1 n
     FROM s as LastInRange
     WHERE LastInRange.n > FirstInRange.n
        AND not EXISTS(SELECT * 
         FROM s as NextInRange 
         WHERE NextInRange.n = LastInRange.n + 1)
     ORDER BY n asc) as end_n            
FROM s as FirstInRange
WHERE NOT EXISTS(SELECT * 
 FROM s as PreviousInRange 
  WHERE PreviousInRange.n = FirstInRange.n - 1);

To work on PostgreSQL (should work on MySQL and probably any database supporting limit) would require a minor adjustment:

-- PostgreSQL implementation (any version)
-- Should work on MySQL (any version) as well
SELECT
FirstInRange.n as start_n,
(SELECT n
 FROM s as LastInRange
 WHERE LastInRange.n > FirstInRange.n
    AND  NOT EXISTS(SELECT * 
     FROM s as NextInRange 
     WHERE NextInRange.n = LastInRange.n + 1)
 ORDER BY n asc LIMIT 1) as end_n            
FROM s as FirstInRange
   WHERE not exists(SELECT * 
     FROM s as PreviousInRange 
     WHERE PreviousInRange.n = FirstInRange.n - 1);