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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:24:09+00:00 2026-06-08T17:24:09+00:00

I have to do multiple INSERT s of the exact same row except for

  • 0

I have to do multiple INSERTs of the exact same row except for the recipient field, whose value is different for every row. Short of doing a for/each loop in PHP to INSERT the same row but change the recipient field in every iteration, is there a way to more efficiently go about this in MySQL?

  • 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-08T17:24:10+00:00Added an answer on June 8, 2026 at 5:24 pm

    You have a few options. But whether you’ll get the efficiency is something you’ve got to benchmark.

    Method 1: First insert all the rows in one batch, then run an update query on a second loop.

    I don’t like this approach since the efficiency is lost in trying to run a second set of update queries.

    But since you’re going to be using PHP to run the queries, I’d advice method 2.

    Method 2:

    1. Build a string to include multiple insert values.

      Insert into MyTable (Field1, Field2, … Field-N)
      Values (Value1, Value2, Value3, … Value-N),
      (Value1, Value2, Value3, … Value-N),
      (Value1, Value2, Value3, … Value-N)

      You may build the string to a substantial size here. I’ve built it for 10,000 records in the past.

    2. Execute the query by calling the mysql_query function.

    3. Go back to step 1 until you have no more records to insert.

    This method is pretty good if you have huge amounts of inserts. But it’s important to keep in mind that a fail in the Insert must be trapped to ensure that the correct records are being inserted. Ideally, a transaction commit would help solve this along with the mysql_affected_rows function.

    And finally, if your numbers aren’t so great, build a smaller string. And if your total records is just around fifty or so, just insert them individually.

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

Sidebar

Related Questions

I have a stored procedure with multiple insert/select statements. Let's say I'm using the
i have script for insert multiple rows : protected static final String INSERT_NAME_LIST1 =
I have the following code to insert multiple products and prices before submitting the
What happens in mysql multiple records insert during an error. I have a table:
I have a PHP function which inserts multiple records into MySQL: function commit_purchase($asset_type_ID, $org_ID,
I have a SQL query where I want to insert multiple rows in single
I been trying all day to do multiple insert for the same form based
Brief: Based on a query, I have multiple checkboxes generated dynamically. The value of
I have a program in which I need to run multiple insert statements (dynamically
I have multiple If statements that if true, inserts data into the db. The

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.