Jump to content

cant update table from another table


manhattes
 Share

Recommended Posts

I am trying to set a column equal to the column in another table where the date matches. I seem to have a problem in my query and I have tried multiple methods. Can someone tell me where the mistake is?

 

$query2 = "UPDATE  a
  SET a.CalDatePrice = b.Close
  FROM ". $symbol ." b
  INNER JOIN CleanedCalendar a
  ON a.BuyDate = b.Date";
 
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM CLBS b INNER JOIN CleanedCalendar a ON a.BuyDate = b.Dat' at line 3
Link to comment
Share on other sites

You are mixing DELETE, UPDATE and SELECT syntaxes in the vain hope of getting something to work. Have you tried reading the manual?

 

http://dev.mysql.com/doc/refman/5.6/en/update.html

 

You'll find it should be like this

UPDATE $symbol b
INNER JOIN CleanedCalendar a
  ON a.BuyDate = b.Date
SET a.CalDatePrice = b.Close
Link to comment
Share on other sites

 

You are mixing DELETE, UPDATE and SELECT syntaxes in the vain hope of getting something to work. Have you tried reading the manual?

 

http://dev.mysql.com/doc/refman/5.6/en/update.html

 

You'll find it should be like this

UPDATE $symbol b
INNER JOIN CleanedCalendar a
  ON a.BuyDate = b.Date
SET a.CalDatePrice = b.Close

That gives me an internal server error.

 

Looking at the syntax page, it would appear it should be formatted like this:

 

$query2 = "UPDATE CleanedCalendar,  ". $symbol ."
   SET CleanedCalendar.CalDatePrice = ". $symbol .".Close
WHERE CleanedCalendar.BuyDate = ". $symbol .".Date";
 
However this also gives an internal Server error
Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

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.

 Share

×
×
  • 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.