Is there a way to limit a query based on the result of another in sqlite?

50 Views Asked by At

I'm searching for something similar to this question, but for sqlite3. Is this possible?

1

There are 1 best solutions below

0
forpas On BEST ANSWER

From SELECT/The LIMIT clause:

Any scalar expression may be used in the LIMIT clause, so long as it evaluates to an integer or a value that can be losslessly converted to an integer...

You can use directly the integer result of a subquery in the LIMIT clause:

SELECT * 
FROM table1
ORDER BY id
LIMIT (SELECT COUNT(*) FROM table2);

See a simplified demo.