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

  • SEARCH
  • Home
  • 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 7766695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:29:13+00:00 2026-06-01T15:29:13+00:00

I was having a look at this question: Getting random value from a SQLite

  • 0

I was having a look at this question: Getting random value from a SQLite table and it got me wondering if one can duplicate records using SQL. More specifically, is there a construct that allows to transform these records:

id| name| count
---------------
 1| Anne|     3
 2|  Joe|     2

into:

id| name
--------
 1| Anne
 1| Anne
 1| Anne
 2|  Joe
 2|  Joe

where the count of Anne and Joe records in the latter matches the corresponding count value in the former set of records.

Can it be done with SQL? If so, how?

EDIT:

Lucero asks what SQL dialect; any really, but ideally the most agnostic approach would be the best.

ANOTHER EDIT:

Can it be done within a single SQL statement in say sqlite?

  • 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-06-01T15:29:15+00:00Added an answer on June 1, 2026 at 3:29 pm

    You can use a “numbers” table (it’s handy for various operations):

    CREATE TABLE num
    ( i UNSIGNED INT NOT NULL
    , PRIMARY KEY (i)
    ) ;
    
    INSERT INTO num (i)
    VALUES
      (1), (2), ..., (1000000) ;
    

    Then:

    SELECT 
        t.id, t.name
    FROM 
            tableX AS t
        JOIN
            num
                ON num.i <= t."count"
    

    Warning: There is of course a limitation on this approach. The query will not produce all the wanted rows, as soon as you have a value in the count column that exceeds the maximum value stored in the Numbers table. If the values in the count column are unbounded, then only an iterative or recursive solution (like the other two answers) can work.

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

Sidebar

Related Questions

Having a look at BDD frameworks and I can't help but wonder which one
I was having a look at this tutorial at Sun on command line I/O.
Hello I am having a hard time making this UI element look the way
I've been having a look at making changes to the partial classes generated from
Can anyone recommend a free grid/graphing component for C#/.NET? I'm having a look at
I'm having trouble getting phong shading to look right. I'm pretty sure there's something
I realize that there are many questions similar to this one, but having looked
Solved this ages ago, but this question recently got some attention so I'm adding
I was having a look over this page: http://www.devbistro.com/tech-interview-questions/Cplusplus.jsp , and didn't understand this
I'm having trouble getting this simple query to execute. I'm using nameless parametized queries

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.