Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6545923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:38:44+00:00 2026-05-25T11:38:44+00:00

Is there any loop statements in SQLite like FOR .. in .. LOOP or

  • 0

Is there any loop statements in SQLite like FOR .. in .. LOOP or something like that? I have two columns StartRange, EndRange and I need to insert a whole sequence in the other table. So if StartRange is 1 and EndRange is 3 it’s necessary to make three inserts with the values 1, 2, 3.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:38:45+00:00Added an answer on May 25, 2026 at 11:38 am

    You can do this sort of thing in straight SQL if you have an extra table that holds all the integers that you need.

    Suppose your StartRange and EndRange range between one and ten and you have a table like this:

    sqlite> select i from ints;
    i
    1
    .
    .
    .
    10
    

    This table simply contains all the possible integers that you need (i.e. one through ten).

    Then if you also have this:

    sqlite> create table t (startrange int not null, endrange int not null);
    sqlite> insert into t values(1, 3);
    sqlite> create table target (i int not null);
    

    You can do your INSERTs into target with a join:

    insert into target (i)
    select ints.i
    from ints join t on (ints.i >= t.startrange and ints.i <= t.endrange)
    

    The result is this:

    sqlite> select * from target;
    i
    1
    2
    3
    

    Of course your real t would have more rows so you’d want a WHERE clause to limit which row of t you look at.

    Similar things are often done with dates (look up “calendar tables”).

    So if your ranges are small (for some definition of small) then generate your ints table once, add an index to it, and use the above technique to do all the INSERTs right inside the database. Other databases have their own ways (such as PostgreSQL’s generate_series) to do this sort of thing without need an explicit ints table but SQLite is (intentionally) limited.

    SQL is generally set-based so loops aren’t natural. What is natural is building the appropriate sets by describing what you need. OTOH, sometimes unnatural acts are necessary and sensible.

    I don’t know if this makes sense for your application, I just thought I’d demonstrate how it can be done. If this approach doesn’t make sense in your case then you can generate a bunch of INSERT statements outside the database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a math problem which is written like this: x^1+x^2+x^3+...+x^n Are there any
Is there any performance hit for writing a function such that local var statements
Is there any reason why I couldn't include two mysql_fetch_array statements working on two
Is there any way to clean up this type of loop using LINQ? List<Car>
Is there any free or commercial component written in .NET (no COM interop) that
I have a code snippet like this myhash.each_value{|subhash| (subhash['key]'.each {|subsubhash| statement that modifies the
As many of you may know, when you have a while loop (or any
There is a table contains columns like username,settings1,settings2,settings3 username is a unique and settings1,2,3
Is there any way to check whether a file is locked without using a
Is there any query which can return me the number of revisions made to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.