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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:08:56+00:00 2026-06-08T12:08:56+00:00

I am wondering if it is possible to perform a SQL query then update

  • 0

I am wondering if it is possible to perform a SQL query then update another table with the generated ID and continue through all of the rows?

I have this SQL query that works but what I need to do is after each row is added to cards to then update merged.cars_id with the last generated ID so they are linked. normally I would do this with PHP but ideally I would like to just do it with MySQL if possible.

MAIN QUERY

INSERT INTO cards (first_contact_date, card_type, property_id, user_id)
SELECT first_contact_date, 'P', property_id, user_id FROM merged

THEN I NEED WITH MATCHING ROWS (Roughly)

 UPDATE merged SET merged.card_id = LAST_INSERT_ID (FROM ABOVE) into the matching record..

Is something like this possible and how do I do it?

  • 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-08T12:08:57+00:00Added an answer on June 8, 2026 at 12:08 pm

    I would recommend using MySQL triggers to do this
    http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html

    A trigger is a function that will be executed AFTER or BEFORE the INSERT or DELETE or UPDATE is done over any record of your table.

    In your case you need to do a AFTER INSERT on cards that just updates the merged table. Make sure its AFTER insert as you wont be able to access the new row’s ID otherwise.

    The code would look something like this, assuming the id field from the cards table its named “id”

    delimiter |
    
    CREATE TRIGGER updating_merged AFTER INSERT ON cards
      FOR EACH ROW BEGIN
        UPDATE merged SET card_id = NEW.id;
      END;
    |
    delimiter ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wondering if its possible to have a an (||)or or (&&)and operator
I was wondering if it were possible to perform an operation on every element
I wondering if it's possible to get the MatchData generated from the matching regular
I am wondering if it is possible to have a socket with send which
I was wondering if its possible to have one or more functions within a
I was wondering if it was possible to perform a ttest (proc ttest) over
I'm wondering if its possible to have an inorder tree traversal method in java
I was wondering if it is possible to perform a certain number of operations
I was wondering if would be possible to perform an action for each time
I was wondering ( if possible ) if there was a program/tool/utility that when

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.