Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select numbers between a range (1 to 100) in sqlite

Tags:

I know some of the solutions in SQL but couldn't find any of them from SQlite.

I just want to execute a select query that returns a resultset of numbers ranging from 1 to 100.

Numbers
  1
  2
  3
  4
  ......
  5

A correction: I don't actually have a table at all. (however a solution is encouraged with a virtual table like dual in MySQL)

like image 480
RamaKrishna Chunduri Avatar asked Nov 22 '10 13:11

RamaKrishna Chunduri


People also ask

How do I SELECT a specific range in SQL?

The SQL BETWEEN Operator The BETWEEN operator selects values within a given range. The values can be numbers, text, or dates. The BETWEEN operator is inclusive: begin and end values are included.

How do I limit query results in SQLite?

You use the LIMIT clause to constrain the number of rows returned by the query. For example, a SELECT statement may return one million rows. However, if you just need the first 10 rows in the result set, you can add the LIMIT clause to the SELECT statement to retrieve 10 rows.

How do I get all the numbers between two numbers in SQL?

Type='P' filter is required to prevent duplicate numbers. With this filter the table will return numbers 0 - 2047. So "number between @min and @max" filter will work as long as the variables are within that range. My solution will allow you to get up to 2048 rows within integer range (-2,147,483,648) - (2,147,483,647).


2 Answers

Thanks sgmentzer! Inspired by your answer I went ahead and also found this:

WITH RECURSIVE
  cnt(x) AS (
     SELECT 1
     UNION ALL
     SELECT x+1 FROM cnt
      LIMIT 100000
  )
SELECT x FROM cnt;
like image 78
Peter Segerstedt Avatar answered Sep 28 '22 10:09

Peter Segerstedt


How about

SELECT * FROM myTable WHERE myNumber >= 1 AND myNumber <= 100;

?

like image 23
BastiBen Avatar answered Sep 28 '22 11:09

BastiBen