Jump to content

[SOLVED] Updating Tables


flyup

Recommended Posts

I am trying to update a single table.

 

I've tried using INSERT but there a few fields that don't match the new table structure.

 

Is there a query that updates identical fields and will skip over fields that aren't in the new table structure?

 

Thanks a lot.

Link to comment
Share on other sites

"table1" is the old table.  "table2" is the new table and includes some fields that are not in "table1"

 

Thanks again. 

 

FIELDS in table1:

 

`id`, `type`, `cid`, `locid`, `stid`, `cnid`, `agent_id`, `mls_id`, `viewad`, `viewbooking`, `bookinglink`, `unit_num`, `street_num`, `address1`, `address2`, `postcode`, `county`, `price`, `showprice`, `freq`, `bond`, `priceview`, `age`, `landtype`, `frontage`, `depth`, `bedrooms`, `totalrooms`, `livingarea`, `bathrooms`, `parking`, `mapref`, `declat`, `declong`, `vtour`, `com_feature`, `adline`, `propdesc`, `smalldesc`, `image1`, `image2`, `image3`, `image4`, `image5`, `image6`, `image7`, `image8`, `image9`, `image10`, `image11`, `image12`, `ctown`, `ctport`, `schooldist`, `preschool`, `primaryschool`, `highschool`, `university`, `hofees`, `custom1`, `custom2`, `custom3`, `custom4`, `custom5`, `pool`, `fplace`, `bbq`, `gazebo`, `lug`, `bir`, `heating`, `airco`, `shops`, `schools`, `elevator`, `pets`, `extra1`, `extra2`, `extra3`, `extra4`, `extra5`, `extra6`, `extra7`, `extra8`, `openhouse`, `ohouse_desc`, `takings`, `returns`, `netprofit`, `bustype`, `bussubtype`, `stock`, `fixtures`, `fittings`, `squarefeet`, `percentoffice`, `percentwarehouse`, `loadingfac`, `fencing`, `rainfall`, `soiltype`, `grazing`, `cropping`, `irrigation`, `waterresources`, `carryingcap`, `storage`, `services`, `listdate`, `lastupdate`, `expdate`, `hits`, `sold`, `published`, `checked_out`, `checked_out_time`, `editor`, `owner`, `premium`, `featured`, `metadesc`, `metakey`

 

FIELDS in table2:

 

`id`, `type`, `cid`, `locid`, `stid`, `cnid`, `locality`, `state`, `country`, `office_id`, `mls_id`, `mls_agent`, `viewad`, `viewbooking`, `bookinglink`, `unit_num`, `street_num`, `address2`, `postcode`, `county`, `price`, `showprice`, `freq`, `bond`, `closeprice`, `priceview`, `age`, `landtype`, `frontage`, `depth`, `bedrooms`, `totalrooms`, `livingarea`, `bathrooms`, `parking`, `stories`, `mapref`, `declat`, `declong`, `vtour`, `adline`, `propdesc`, `smalldesc`, `image1`, `image2`, `image3`, `image4`, `image5`, `image6`, `image7`, `image8`, `image9`, `image10`, `image11`, `image12`, `image1desc`, `image2desc`, `image3desc`, `image4desc`, `image5desc`, `image6desc`, `image7desc`, `image8desc`, `image9desc`, `image10desc`, `image11desc`, `image12desc`, `image13`, `image14`, `image15`, `image16`, `image17`, `image18`, `image19`, `image20`, `image21`, `image22`, `image23`, `image24`, `image13desc`, `image14desc`, `image15desc`, `image16desc`, `image17desc`, `image18desc`, `image19desc`, `image20desc`, `image21desc`, `image22desc`, `image23desc`, `image24desc`, `ctown`, `ctport`, `schooldist`, `preschool`, `primaryschool`, `highschool`, `university`, `hofees`, `custom1`, `custom2`, `custom3`, `custom4`, `custom5`, `custom6`, `custom7`, `custom8`, `pool`, `fplace`, `bbq`, `gazebo`, `lug`, `bir`, `heating`, `airco`, `shops`, `schools`, `elevator`, `pets`, `furnished`, `extra1`, `extra2`, `extra3`, `extra4`, `extra5`, `extra6`, `extra7`, `extra8`, `openhouse`, `ohouse_desc`, `takings`, `returns`, `netprofit`, `bustype`, `bussubtype`, `stock`, `fixtures`, `fittings`, `squarefeet`, `percentoffice`, `percentwarehouse`, `loadingfac`, `fencing`, `rainfall`, `soiltype`, `grazing`, `cropping`, `irrigation`, `waterresources`, `carryingcap`, `storage`, `services`, `listdate`, `lastupdate`, `expdate`, `closedate`, `contractdate`, `hits`, `sold`, `published`, `checked_out`, `checked_out_time`, `editor`, `owner`, `premium`, `featured`, `metadesc`, `metakey`, `currency_position`, `currency`, `currency_format`, `assoc_agent`, `email_status`, `ordering`, `schoolprof`, `hoodprof`, `pdfinfo`, `ohdate`, `ohstarttime`, `ohendtime`, `offpeak`

Link to comment
Share on other sites

I understand...  So you are saying mySQL doesn't have a command that basically says, UPDATE the table if the fields are the same and if they aren't don't do anything?

 

You would have to write something that included all these fields for both the old and new table?

 

That kinda blows. 

Link to comment
Share on other sites

I was trying to avoid overwriting because I want to use the new fields for additional data.

 

When you say overwrite you mean the INSERT..  SELECT query would update the identical fields but delete the fields that are different in the 2nd table?

 

Hey, thanks a lot for your time.  I really do appreciate it.

Link to comment
Share on other sites

INSERT...SELECT would INSERT new data, but it wouldn't UPDATE anything in the table you're inserting into. But the tables are such a mess it's hard to really say update. It's not impossible though. Depends on your definition of update.

Link to comment
Share on other sites

Hey,

 

I'm using the INSERT query after dropping the tables that don't apply and I'm getting this error:

 

#1062 - Duplicate entry '1' for key 'PRIMARY'

 

What can I do to make the INSERT command work?

 

 

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.