Jump to content

Update one field by selecting values from two other tables, very confused here


beejeebers

Recommended Posts

I am using this: MySQL client version: 4.1.22

 

Here's the tables:

 

kw_log

-------

rotation_name

network_offer

 

rotations

---------

rotation_name

offer_id

 

offers

-----

id

network_offer

 

I screwed up my initial table design in the kw_log table and need to run an update statement to fill in the value for the rotation_name in the kw_log table.

 

The rotation_name is in the rotations table, along with the offer_id which is the same as the id in the offer table. The only way I can see to figure out what rotation_name to base the field value on is to match the network_offer values in the offers and kw_log tables. (Hope this makes sense as I'm lost on how to do this...)

 

I think it's possible using joins but am clueless here...any help is appreciated.  I have tried the following so far:

 

UPDATE kw_log SET rotation_name = rotation_name_to_update WHERE (

SELECT rotations.rotation_name AS rotation_name_to_update

FROM rotations, offers

WHERE rotations.offer_id = offers.id

)

 

Didn't work, it said:

 

#1054 - Unknown column 'rotation_name_to_update' in 'field list'

 

I'm just not sure what to set the field to...

 

so I tried this:

 

UPDATE kw_log SET rotation_name = ( SELECT rotations.rotation_name AS rotation_name_to_update

FROM rotations, offers

WHERE rotations.offer_id = offers.id )

 

that didn't work either it said:

 

#1242 - Subquery returns more than 1 row

 

Which is true, but I still want to update that rotation_name field in the kw_log table...

 

I've also tried this:

 

UPDATE kw_log SET rotation_name = rotations.rotation_name

WHERE rotations.offer_id = offers.id

 

But that didn't work, it said:

 

#1109 - Unknown table 'rotations' in where clause

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.