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 139317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:24:47+00:00 2026-05-11T07:24:47+00:00

I have a number of rows from a database which I want to insert

  • 0

I have a number of rows from a database which I want to insert into another database. Since there’s quite a few rows I want to use the INSERT .. SELECT … construct in mysql. The statement I try to run is as follows:

set @rank := 1; set @currpoints := 0; set @currgroupcount := 0;    SELECT id, @rank := if( @currpoints = points, @rank , @rank + @currgroupcount )   AS rank,    @currgroupcount := if( @currpoints = points, @currgroupcount +1, 1 ) , @currpoints :=    points FROM characters ORDER BY points DESC , name LIMIT 0 , 30 

The problem is that I can’t insert the selected rows into the database when the result has more than two columns. Is there any way I can do these needed increments without returning the expressions as columns? If it isn’t possible do you know what i can do as an alternative and still be able to get the performance gain that lies in using the INSERT .. SELECT … construct?

  • 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. 2026-05-11T07:24:48+00:00Added an answer on May 11, 2026 at 7:24 am
    INSERT INTO new_characters (id, name) SELECT id, name FROM (   SELECT id,   @rank := if( @currpoints = points, @rank , @rank + @currgroupcount ) AS rank,    @currgroupcount := if( @currpoints = points, @currgroupcount +1, 1 ),   @currpoints := points   FROM characters   ORDER BY points DESC , name   LIMIT 0 , 30 ) m 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have need to select a number of 'master' rows from a table, also
I have a database table with a large number of rows and one numeric
I have a LinqDataSource that I use to calculate the number of rows in
I have a web based program which chooses some records from a database using
In the database there are column values which appear in multiple rows. The example
I have a SQL Server database and I want to define a query which
I have a php array to display information from a database. I want to
I have a system which will return all users from the database and order
I have a number of tracks recorded by a GPS, which more formally can
I have a number of data classes representing various entities. Which is better: writing

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.