MySQL INSERT SELECT not Inserting - mysql

I am trying tor un an insert select that looks like this:
INSERT INTO users_extension_usage (userid, extensionid, complete)
SELECT '3', extensions.id FROM extensions WHERE extensions.folder='definitions', '1'
however it has a problem when I run it in phpMyAdmin that refers to the '1':
#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 ' '1'' at line 2
I have tried many different combinations of SELECT, INSERT etc but I cat see the problem. I have looked at any different posts on here and other forums too but alas most suggest the syntax I am using!
I have tried to set up an SQL Fiddle here: http://sqlfiddle.com/#!9/9f460
Any suggestions for how this might work will be gratefully accepted :)

You are missing the third column:
INSERT INTO users_extension_usage(userid, extensionid, complete)
SELECT '3', extensions.id, '1' as complete
FROM extensions
WHERE extensions.folder = 'definitions';
The '1' belongs in the SELECT statement, not after the WHERE.

Related

select inside insert with more data to be inserted

I'm facing a problem with select inside insert statements.
I've take a look at the questions similar to this but still the query is not working.
first, I'm working with MySQL version 5.6.24 with engine InnoDB, and I'm trying to insert this row:
INSERT INTO form (SELECT course_name FROM course WHERE course_id ='1' ), '123456','5','3','6','1','3','6','1','2','5','6','1','4','1','2','3','good','not bad','bad')
I want the first column to be retrieved (which is only one value), but not the other.
I've tried many syntax formats, with VALUES, with semicolon, with more parentheses, etc... but non work. Here is 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 ' '123456','5','3','6','1','3','6','1','2','5','6','1','4','1','2','3','good','no' at line 1
Thanks.
Use an INSERT-SELECT:
INSERT INTO form
SELECT course_name, '123456','5','3','6','1','3','6','1','2','5','6','1','4','1','2','3','good','not bad','bad'
FROM course
WHERE course_id = '1'

SQL INSERT INTO Error #1064 on phpMyAdmin

My code keeps giving me the following 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 'INSERT INTO tags (id, name) VALUES (1, 'Web Design')' at
line 2
I'm running the code on phpMyAdmin. Here is the code:
USE home_blog
INSERT INTO tags (`id`, `name`)
VALUES (1, 'Web Design');
id is an int and name is a varchar. I found similar problems, but they were all fixed by reserved word issues or missing parentheses. Unless I'm completely blind I don't those issues.
USE and INSERT are 2 different statements, like 2 queries. You need to write ";" at the very end of all statements if you want to execute them in the row.

Update a column on rows of which another column has multiple values

I am having trouble with something like this:
UPDATE `database` SET `col1` = 0 WHERE `col2` in (1,2,3,4);
Following is an actual failed query.
Error Message:
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 '#cc3.biz, sales#allservico.com)' at line 1
SQL:
UPDATE `CubeCart_customer` SET `optIn1st` = 0 WHERE `email` in (markscarts#cc3.biz, sales#allservico.com);
I have searched the web, and here, and tried several variations in my code to produce the query, but I just can't pinpoint where I'm failing.
Any light on this matter would be greatly appreciated.
You need quotes around your string values
UPDATE CubeCart_customer
SET optIn1st = 0
WHERE email in ('markscarts#cc3.biz', 'sales#allservico.com');

Mysql Subquery Outer Where

Im trying to write a mysql query that will find the value to insert via a sub query and only insert into the row that has the id that is specified mysql is giving me this 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 'WHERE product_id = '1'' at line 8
But i don now know what the synax should be any help is appreciated bellow is my current query.
Lewis
INSERT INTO oc_product
(tax_class_id)
(
SELECT tax_class_id
FROM oc_tax_class
WHERE title = 'Taxable Goods'
)
WHERE product_id = '1'
EDIT: im a moron and i should have been using UPDATE not insert its fixed now.
If I'm understanding your question correctly, I think you or looking to insert a new row with product id = 1:
INSERT INTO oc_product (product_id, tax_class_id)
SELECT 1, tax_class_id
FROM oc_tax_class
WHERE title = 'Taxable Goods'

You have an error in your SQL syntax

I am getting this 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 '"insert into hall_booking(name,address,event_type,hallNo,arrival_time,arrival_da' at line 1
When running this query:
insert into hall_booking (
name,address,event_type,hallNo,arrival_time,arrival_date,dep_time,dep_date,identity,emailid,contact,total_members,desc,catering,service,decoration,other
) values (
'$nm','$add','$typ','$roomno','$arrv','$arrivaldate','$departure','$dDate','$idt','$emailid','$cont','$desc','200','200','200','200')
Again a problem occured in sql statement. What mistake i did?
You look as if you're using protected keywords as column names (you shouldn't really do this).
Try escaping them with `
insert into hall_booking (
name,address,event_type,hallNo,arrival_time,
arrival_date,dep_time,dep_date,`identity`,
emailid,contact,total_members,`desc`,catering,service,decoration,other)
values(
'$nm','$add','$typ','$roomno','$arrv',
'$arrivaldate','$departure','$dDate','$idt',
'$emailid','$cont','$desc','200','200','200','200')
Try this:
insert into hall_booking (name,address,event_type,hallNo,arrival_time,arrival_date,dep_time,dep_date,identity,emailid,contact,total_members,desc,catering,service,decoration,other)
values ( '".$nm."','".$add."','".$typ."','".$roomno."','".$arrv."','".$arrivaldate."','".$departure."','".$dDate."','".$idt."','".$emailid."','".$cont."','".$desc."','200','200','200','200')"
You are getting this error because you are using a reserved keyword desc as a column name. To overcome this error you can replace your query with the following one:
insert into hall_booking (name,address,event_type,hallNo,arrival_time,arrival_date,dep_time,dep_date,`identity`,emailid,contact,total_members,`desc`,catering,service,decoration,other) values ('$nm','$add','$typ','$roomno','$arrv','$arrivaldate','$departure','$dDate','$idt','$emailid','$cont','$desc','200','200','200','200')"
Also you can refer this article for more clarification:
How do I escape reserved words used as column names? MySQL/Create Table
I think you have not mentioned last value
"INSERT INTO `hall_booking`(`name`,`address ,`event_type`,`hallNo`,`arrival_time`,`arrival_date`,`dep_time`,`dep_date`,`IDENTITY`,`emailid`,`contact`,`total_members`,`DESC`,`catering`,`service`,`decoration`,`other`)
VALUES('".$nm."',
'".$add."',
'".$typ."',
'".$roomno."',
'".$arrv."',
'".$arrivaldate."',
'".$departure."',
'".$dDate."',
'".$idt."',
'".$emailid."',
'".$cont."',
'".$desc."',
'200',
'200',
'200',
'200',
'Last Value')"
You have a field which is a reserved word... desc.
Try to enclosed it with '`' character so it should be `desc`.
mysql>
insert into hall_booking
(name,address,event_type,hallNo,arrival_time,
arrival_date,dep_time,dep_date,identity,emailid,contact,total_members,
`desc`,catering,service,decoration,other) values
('$nm','$add','$typ','$roomno','$arrv','$arrivaldate','$departure','$dDate',
'$idt','$emailid','$cont','$desc','200','200','200','200')