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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:43:09+00:00 2026-06-13T20:43:09+00:00

It is easy to insert a row into a MySQL table from another MySQL

  • 0

It is easy to insert a row into a MySQL table from another MySQL table:

INSERT INTO sometable (SELECT * FROM anothertable WHERE somefield='somevalue')

but how do I do this if I want to update instead of insert? I’m looking for something similar to

UPDATE sometable SET (SELECT * FROM anothertable WHERE somefield='somevalue')

Obviously, this doesn’t work. (The structures of sometable and anothertable are identical).

  • 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-13T20:43:11+00:00Added an answer on June 13, 2026 at 8:43 pm

    If you’re trying to update rows based specifically on matches of the primary key, then you can use REPLACE instead of INSERT.

    REPLACE INTO sometable SELECT * FROM anothertable WHERE somefield='somevalue';
    

    This means when the primary key column from anothertable has the same value as the primary key column in sometable, then all the other columns returned by the SELECT are used to overwrite those columns in sometable.

    See http://dev.mysql.com/doc/refman/5.5/en/replace.html

    If the row matching is based on something other than primary key, you’ll have to use multi-table UPDATE syntax as @John Woo showed.

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

Sidebar

Related Questions

I want to insert multiple values into a row, but I want to make
An easy problem, but for some reason I just can't figure this out today.
So, here's the problem (it's probably an easy one :P) This is my table
I am trying to insert an image into a table cell based off a
This should be really easy but I am struggling. Here is my current code
Not sure if there a way of doing this, but I can insert multiple
With jquery it's very easy to insert some element inside another element using the
This is the code: $sql = SELECT * FROM blad1 order by RAND() LIMIT
Seems like this should be easy but I must just be missing something... I
Is there an easy way to INSERT a row when it does not exist,

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.