SQLite Forum

Can this SQL be simplified?
Login
I have this which gives me expected results:

select id from T2 order by mydate limit case when (select count(*) from T2)>(select maxrows from T1) then (select count(*) from T2)-(select maxrows from T1) else 0 end;

This returns the excess oldest rows in T2 (each row has a date stamp) if there are more than maxrows in T2, otherwise no rows.

Is there a way to avoid repeating the selects in the 'then' portion? I tried using 'as' but can't see how to use the column-aliases.