dbaspot
Tags Register FAQ Calendar Search Today's Posts Mark Forums Read

Update field through relationship? - mysql

This is a discussion on Update field through relationship? - mysql ; I have a two-table relationship and I want to get rid of one table. I have a table of surveys, where each row is related to one row in a table of access codes. These are the relevant fields: Surveys.access_code_id ...


Home > Database Forum > Other Databases > mysql > Update field through relationship?

Reply

 

LinkBack Thread Tools Display Modes
  #1  
Old 11-14-2008, 01:52 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Update field through relationship?

I have a two-table relationship and I want to get rid of one table.

I have a table of surveys, where each row is related to one row in a
table of access codes. These are the relevant fields:

Surveys.access_code_id
AccessCodes.id
AccessCode.valid_date

We are moving to a new method of access validation, so we don't need
the table of AccessCodes anymore. I want to add the field
Surveys.valid_date, and update the value with the appropriate value
from the AccessCodes table, before I delete it.

So I want to do something like

UPDATE Surveys SET Surveys.valid_date = SELECT valid_date FROM
AccessCodes WHERE AccessCodes.id = Surveys.access_code_id

Is this the proper syntax? I'm hesitant to play around with UPDATE
queries!
Reply With Quote
  #2  
Old 11-14-2008, 02:31 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Update field through relationship?

On Nov 14, 12:52*pm, lawpoop wrote:

>
> So I want to do something like
>
> UPDATE Surveys SET Surveys.valid_date = SELECT valid_date FROM
> AccessCodes WHERE AccessCodes.id = Surveys.access_code_id
>
> Is this the proper syntax? I'm hesitant to play around with UPDATE
> queries!


I did some testing with some test tables, and this works:

UPDATE Surveys SET survey_date = ( SELECT `date` FROM AccessCodes
WHERE AccessCodes.id = Surveys.access_code_id );


Reply With Quote
Reply

Thread Tools
Display Modes



All times are GMT -4. The time now is 05:06 AM.