Jump to content

ERROR on : UPDATE table_1 LEFT JOIN table 2...


AndrewAMO

Recommended Posts

Hi Everyone,
I need help figuring out how to update one table with info from another. My code is
UPDATE sampleIDS
LEFT JOIN simpleSamples ON ( simpleSamples.`textualDateTime` = sampleIDS.`textualDateTime`
AND simpleSamples.`samplingConditions` = sampleIDS.`samplingConditions` )
SET sampleIDS.`soilSampleID`=simpleSamples.`soilSampleID`

When executing this in phpMyAdmin I get an error LEFT JOIN simpleSamples. If you say SELECT * FROM instead of UPDATE and leave off the SET... stuff it works. Can someone please help me with this error?
-Andrew
Link to comment
Share on other sites

Ok for the create sampleIDS table (4000 entrys):
CREATE TABLE `ajk60330DELETE`.`sampleIDS` (
`soilSampleID` int( 11 ) NOT NULL default '0',
`locationID` int( 11 ) NOT NULL default '0',
`sampleDate` date default NULL ,
`sampleTime` time default NULL ,
`textualDateTime` varchar( 255 ) NOT NULL default '',
`soilSampleName` varchar( 50 ) NOT NULL default '',
`collector` varchar( 50 ) NOT NULL default '',
`depthcm` float NOT NULL default '0',
`topDepthcm` float default NULL ,
`samplingConditions` varchar( 255 ) default NULL ,
`snowCover` char( 1 ) default NULL ,
`snowDepthcm` float NOT NULL default '0',
`referenceDoc` varchar( 50 ) NOT NULL default '',
`samplingMethod` text NOT NULL ,
`owner` varchar( 25 ) NOT NULL default '',
`dataset` varchar( 25 ) NOT NULL default '',
KEY `samplingConditions` ( `samplingConditions` ) ,
KEY `textualDateTime` ( `textualDateTime` ) ,
KEY `soilSampleID` ( `soilSampleID` )
) TYPE = MYISAM ;


For the simpleSamples (50 entrys):
CREATE TABLE `ajk60330DELETE`.`simpleSamples` (
`soilSampleID` int( 11 ) NOT NULL default '0',
`locationID` int( 11 ) NOT NULL default '0',
`sampleDate` date default NULL ,
`sampleTime` time default NULL ,
`textualDateTime` varchar( 255 ) NOT NULL default '',
`soilSampleName` varchar( 50 ) NOT NULL default '',
`collector` varchar( 50 ) NOT NULL default '',
`depthcm` float NOT NULL default '0',
`topDepthcm` float default NULL ,
`samplingConditions` varchar( 255 ) default NULL ,
`snowCover` char( 1 ) default NULL ,
`snowDepthcm` float NOT NULL default '0',
`referenceDoc` varchar( 50 ) NOT NULL default '',
`samplingMethod` text NOT NULL ,
`owner` varchar( 25 ) NOT NULL default '',
`dataset` varchar( 25 ) NOT NULL default ''
) TYPE = MYISAM ;
Link to comment
Share on other sites

It may be a version error, though I think I'm running mysql 5.0. I removed the primary keys because I thought it might be the source of the error. Though I have tried the code with them still there.
Since the code works using SELECT * FROM instead of the UPDATE, as a last resort, I think I'm going to just export the joined tables and import the result back into the database. I'm also looking into using the REPLACE function. I'll post if this works.
Link to comment
Share on other sites

Are you sure you want to use a LEFT JOIN? soilSampleID is set to NOT NULL so it will error out when the left joined column comes up NULL.

Try an INNER JOIN and see if it does what you want it to. If not, you'll have to convert the NULL to a 0. I'll help you with that part if you ask.
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.