Jump to content

Want to INSERT into one column that I have added


rocky48
Go to solution Solved by Muddy_Funster,

Recommended Posts

I am trying to INSERT data into a column that I have added to the table, but I keep getting a syntax error.

Here is the line:

INSERT INTO `ctryvisits15`(`Qtr`) VALUES (2) WHERE `WNo` <27

The message is :

#1064 - 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 '2) WHERE `WNo` <27' at line 1

 

I have tried every thing I can think of but can't see where I am going wrong.

I am using phpMyAdmin to update my data.

Link to comment
Share on other sites

cyberRobot is of course correct.  INSERT creates a completely new record, thus WHERE can not be used (there is no existing point of reference for a new record to use in this way).  WHERE can only be used when interacting with existing data (using SELECT, or the suggested UPDATE for example).  It is used to make conditions which reference the existing records in the table so that only the desired records are affected.

 

If you give us a bit more background on what you are doing we can advise further.

Link to comment
Share on other sites

Out of curiosity, do your `ctryvisits15` table rows contain a DATE column for the date of the visit?

 

if so, the week number and quarter columns are redundant. You can derive both those values direct from the date.

mysql> SELECT WEEK('2015-06-11') as wkno;
+------+
| wkno |
+------+
|   23 |
+------+

mysql> SELECT QUARTER('2015-06-11') as qtr;
+------+
| qtr  |
+------+
|    2 |
+------+
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.