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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:53:34+00:00 2026-06-02T12:53:34+00:00

I am trying to copy values directly from one mysql table to another… but

  • 0

I am trying to copy values directly from one mysql table to another… but the trouble is, there are many rows to copy, so that sub-select statement will return many rows but the param :order_id is just written once.

Given that problem, I’m having trouble figuring out how to write this process:

# 1: Create new Order & Copy the cart basket to the Order basket
$order_id = addOrder($customer_id);
if ($order_id > -1) {
    $sql = "INSERT INTO tbl_order_basket(order_id, product_id, product_name,
                                         basket_qty, basket_price, subtotal)
                 VALUES (:order_id, (SELECT (cart.product_id, product.name,
                                     cart.cart_qty, cart.cart_price, cart.subtotal)
                                FROM tbl_shopping_cart AS cart
                          INNER JOIN tbl_product AS product
                                  ON cart.product_id = product.id
                               WHERE cart.php_sesskey = :session_id)
                        )
                  WHERE order_id=:order_id;";
}

Here is the data I’m trying to copy:

ORDER BASKET            CART BASKET         PRODUCTS
FK  order_id            FK  php_sesskey
FK  product_id      <-- FK  product_id  === PK  id
    product_name    <--                 <--     name
    basket_qty      <--     cart_qty
    basket_price    <--     cart_price                              # <-- : copy to
    subtotal        <--     subtotal                                # === : join on

How should I go about doing this?

Note: I’m using PHP 5 and MySQL 5.5

  • 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-02T12:53:40+00:00Added an answer on June 2, 2026 at 12:53 pm

    Maybe you can use this one?

    INSERT INTO ... SELECT ... FROM ... WHERE ...
    

    To create the query, first make a SELECT which gives you all the fields which you want to insert. Then prepend INSERT INTO <table> and you’re done.

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

Sidebar

Related Questions

I am trying to copy some property values from one object to another (both
I am trying to copy data from my MYSQL table to SQL Server using
I am trying to copy a column from one sheet to another. The code
So I am trying to copy alot of data from one woorkbook to another.
I am trying to copy one table over another one atomically. Basically I want
I'm trying to copy the values from a named range in Excel to a
I am trying to copy a structure of folders and subfolders from one Outlook
I'm trying to copy a continuous block of data from one location in the
I am trying to solve copy pasting a column with values from excel into
I'm trying to figure out how to take values from one of these input

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.