I'm trying to run the following statement:
INSERT INTO table (
as,
ad
,af,
ag,
ah,
aj
)
VALUES (
'a',
'b',
'c',
'd',
'e',
'f'
)
ON DUPLICATE KEY UPDATE (
aj='dv',
ah='ev',
ag='fv'
);
and getting the following error:
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 '(ag='dv',ah='ev',ah='fv')'
at line 3
Any advice?
thx
Skip the ()..
INSERT INTO site_domains_meta
(domainname,metatype,pagename,english,indonesian,japanese)
VALUES ('a','b','c','d','e','f')
ON DUPLICATE KEY UPDATE english='dv',indonesian='ev',japanese='fv';
http://dev.mysql.com/doc/refman/5.5/en/insert.html
Related
I have a table called design_designs
The table contains 4 columns: id, key, value, nonceId
I'm attempting to run a query to insert into the table:
INSERT INTO design_designs(key, value, nonceId)
VALUES ('test key', 'test value', 'test nonce');
The error i get is:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'key, value, nonceId)
VALUES ('test key', 'test value', 'test nonce')' at line 1
Any idea what I'm doing wrong? According to the documentation on queries my query is correct. I'm obviously missing something.
key is a reserved word, you must delimit it:
INSERT INTO design_designs(`key`, value, nonceId) VALUES...
Try to use this query
insert into `popups` (`GroupID`, `Name`,`ShortName`) VALUES
(SELECT `GroupID`,`Name`,`ShortName` FROM `temp` WHERE `GroupID` = '1')
#1064 - You have an error in your SQL syntax;
Tables popups and temp almost identical - hase same columns.
What is wrong in request?
It's either insert...values or insert...select in your case drop values
insert into `popups` (`GroupID`, `Name`,`ShortName`)
SELECT `GroupID`,`Name`,`ShortName` FROM `temp` WHERE `GroupID` = '1'
https://dev.mysql.com/doc/refman/8.0/en/insert.html
I first run this Query to INSERT a row
INSERT INTO a (acol, bcol, ccol) VALUES (1, 1, 12);
Then I follow it with
INSERT INTO a (acol, bcol, ccol) VALUES (1, 1, 12)
ON DUPLICATE KEY UPDATE ccol=VALUES(10);
while having UNIQUE KEY on aco, bcol, But I keep getting this error:
SQL Error (1064): You have an error in your SQL syntax;
check the manual that corresponds to your MariaDB server version for the right syntax to use
near '10)' at line 1
Now I tried it at SQLFiddle and got this error:
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 'INSERT INTO a (acol, bcol, ccol) VALUES (1, 1, 12) ON DUPLICATE KEY UPDATE ccol=' at line 3
after adding it.
What is the problem with my Query?
VALUES() in the ON DUPLICATE KEY UPDATE part is used to refer to columns from the INSERT part.
Example:
INSERT INTO a (acol, bcol, ccol) VALUES (1, 1, 12)
ON DUPLICATE KEY UPDATE ccol = VALUES(ccol);
VALUES(ccol) will refer to the value of ccol which you tried to insert. It's 12 in this case.
If you just want to set a constant value, then just use
ON DUPLICATE KEY UPDATE ccol = 10
You can can also mix it and do something like
ON DUPLICATE KEY UPDATE ccol = VALUES(ccol) - 2;
When using On Duplicate KEY UPDATE, use VALUES() only when you need the value of a column. For assigning numbers, it should be assigned without using VALUES()
INSERT INTO a1 (acol, bcol, ccol) VALUES (1, 1, 12) ON DUPLICATE KEY UPDATE ccol= 5;
use
INSERT INTO a (acol, bcol, ccol) VALUES (1, 1, 12)
ON DUPLICATE KEY UPDATE ccol=10;
use TREND_INFORMATION
INSERT INTO log_index_level_1
(LOG_INDEX, LOT_ID, WAFER_ID, MAP_REV, PROBE_DATE)
(42, "2819893.003", "9893-06", "PR20", "2013-07-13");
I keep getting the following error, and I'm not sure what I'm doing wrong here.
The column types are int , varchar, varchar, varchar, and date , respectively.
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL s
er version for the right syntax to use near '42, "asdfasfasf", "asdfas", "tes", '2013-07-13')' at line 3
You're missing the keyword VALUES
INSERT INTO log_index_level_1
(LOG_INDEX, LOT_ID, WAFER_ID, MAP_REV, PROBE_DATE)
VALUES -- <-- That's what you're missing
(42, "2819893.003", "9893-06", "PR20", "2013-07-13");
You forgot the VALUES keyword
INSERT INTO log_index_level_1 (LOG_INDEX, LOT_ID, WAFER_ID, MAP_REV, PROBE_DATE)
VALUES (42, '2819893.003', '9893-06', 'PR20', '2013-07-13');
I'm trying to teach myself MySQL while working on a project at the same time. I'm using phpMyAdmin.
I'm getting the error: "#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 ''ps_category' ('id_category', 'id_parent', 'id_shop_default', 'level_depth', 'nl' at line 1"
My code:
INSERT INTO 'ps_category'
('id_category', 'id_parent', 'id_shop_default',
'level_depth', 'nleft', 'nright', 'active',
'date_add', 'date_upd', 'position', 'is_root_category')
VALUES (6,2,1,0,0,0,1,'2012-04-12 15:12:54','2012-04-12 15:12:54',1,0)
UPDATE:
I took off the single quotes and still getting the same error:
INSERT INTO ps_category
('id_category', 'id_parent', 'id_shop_default',
'level_depth', 'nleft', 'nright', 'active',
'date_add', 'date_upd', 'position', 'is_root_category')
VALUES (6,2,1,0,0,0,1,'2012-04-12 15:12:54','2012-04-12 15:12:54',1,0)
INSERT INTO `ps_category` (`id_category`, `id_parent`, `id_shop_default`, `level_depth`, `nleft`, `nright`, `active`, `date_add`, `date_upd`, `position`, `is_root_category`) VALUES (6,2,1,0,0,0,1,'2012-04-12 15:12:54','2012-04-12 15:12:54',1,0)
You are using a single quote on the table name. It should be ticks or nothing. It should be noted, the ticks help to ensure properly reading the table name. If you name your table a mysql reserved word, the ticks will prevent it from erroring
The table name should not be entered as a string literal, either remove these '' or put two '' and '' around it like so
INSERT INTO ps_category ...
Or
INSERT INTO `ps_category` ...
Table names should not be quoted