Home > Software engineering >  sqlite - get number of rows, and use that information to limit the query
sqlite - get number of rows, and use that information to limit the query

Time:09-21

I would need to limit my query based on the number of rows.

I would like something like this:

select *,
       (select count(id) as cnt from test) as cnt 
from mytable limit (cnt-100)

but I get the error message that cnt is not a column.

How can I change mi limit based on the number of rows present in the db?

CodePudding user response:

You can just use a SELECT statement for that.

SELECT * FROM mytable LIMIT (SELECT COUNT(id)-100 FROM test);
  • Related