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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:56:18+00:00 2026-06-11T05:56:18+00:00

I am trying to figure out how to update a row in one table,

  • 0

I am trying to figure out how to update a row in one table, setting a column value equal to a value in a different table. Here’s an example:

movies:

movie_id | movie_price

movies_attended:

attended_id | attended_movie_id | attended_movie_price

Now, this is kind of a stupid example, but supposed that for some reason there is a row in movies_attended that does not have the correct attended_movies_price in it and so it needs to be updated.

How should a query be written to update the movies_attended table, setting movies_attended.attended_movie_price = movies.movie_price?

I tried something similar to the following, but it did not work:

update movies_attended, movies 
set movies_attended.attended_movie_price = movies.movie_price 
where movies_attended.attended_movie_id = movies.movie_id 
AND attended_id = [the id of the row we want to update]
  • 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-11T05:56:20+00:00Added an answer on June 11, 2026 at 5:56 am

    When you say “it did not work”, do you mean that it reported 0 rows updated, or did the statement cause the database raise an exception?

    Your example statement appears to be of the form:

    UPDATE movies_attended a
      JOIN movies m
        ON a.attended_movie_id = m.movie_id
       SET a.attended_movie_price = m.movie_price
     WHERE a.attended_id = ?
    

    (We typically prefer the JOIN ... ON ... style syntax to the comma join operator and the join predicates in the WHERE clause.)

    I have no explanation as to why this statement would “not work”.

    It’s possible this would report 0 rows affected, if no rows satisfy the predicates. It would also report 0 rows affected if the rows that would be changed do not require any changes… that is, the existing value in attended_movie_price already matches the value being assigned to it.

    Normally, before running an update statement like that, I write it as a SELECT first, and see what values are returned…

    By replacing the UPDATE keyword with SELECT ... FROM, and removing the SET clause:

    SELECT m.movie_price          AS new_val
         , a.attended_movie_price AS old_val
         , a.attended_id
      FROM UPDATE movies_attended a
      JOIN movies m
        ON a.attended_movie_id = m.movie_id
     WHERE a.attended_id = ?
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to figure out how can I update the petevents table with
I've been trying to figure out a way to update the interface after each
I am trying to figure out how I can update my sql query dynamically.
I'm trying to figure out how to ask this - so I'll update the
I'm trying to do a simple update, but can't figure out somthing. I have
Trying to figure out how to type (via events not set the value) on
I'm trying to figure out storage requirements for different storage engines. I have this
I am trying to figure out how to delete one item from this NSMutableArray
for last two days i was trying to figure out how to update a
Trying to figure out how I can do this properly. The print_r looks like

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.