mySQl insert into an exsisting table Syntax Error - mysql

I am trying to add these value in the "employee" table, but it shows me an error that I can't fix, any help?!
The Syntax:
INSERT INTO `employee`( 'UserName',`ID`, `firstname`, `middlename`,'lastname','Address','department','salary','password','phonenumber','email','LoginStatus')
VALUES ('medo',1','ahdjh','rgetrhytyiu','rgthyu','','2','100000','','24741585285','da#hash.com','1')
The error:
Error: INSERT INTO employee( 'UserName',ID, firstname,
middlename,'lastname','Address','department','salary','password','phonenumber','email','LoginStatus')
VALUES
('medo',1','ahdjh','rgetrhytyiu','rgthyu','','2','100000','','24741585285','da#hash.com','1')
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 ''UserName',ID, firstname,
middlename,'lastname','Address','department','sa' at line 1

Try this:
Remove quotes from column--
INSERT INTO employee( UserName,ID, firstname, middlename,lastname,Address,department,salary,password,phonenumber,email,LoginStatus) VALUES ('medo',1','ahdjh','rgetrhytyiu','rgthyu','','2','100000','','24741585285','da#hash.com','1')

Just remove the (username,ID,......)
Directly write
Insert Into Tablename Values(.....);
And in the Values section you have a ` this in the ID field.Remove that as well.

Related

opposite of insert into - removing duplicates

I am very new to Sql, so bear with me. I have run a query the following query:
INSERT INTO adhoc_dt.`table` (id, name) VALUES(53098974, 'John');
however, by accident I run it twice. I would like to remove the duplicate. How can that be done?
I tried
INSERT INTO adhoc_dt.`table` (id, name) VALUES(53098974, 'John');
but get an error:
SQL ERROR [1064][42000]: 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
If your table name include special char of reserved word then you should enclose the table name with backticks:
`table`
But looking to your question, the table name seems:
`adhoc_dt.`table`
In this case, the correct syntax for delete is:
DELETE FROM adhoc_dt.`table`
WHERE id = 53098974 AND name = 'JOHN'
but in this way you delete all the rows with:
id = 53098974 AND name = 'JOHN'
You have to follow steps
truncate table
apply unique constraint on ID
run insert script

INSERT INTO with WHERE?

I'm running this SQL query:
$regSql = "INSERT INTO orderregel(AANTAL) VALUES('$aant') WHERE TAAK_ID='$TkID'";
I also tried this one:
$regSql = "INSERT INTO orderregel(AANTAL) VALUES('$aant') WHERE TAAK_ID=$TkID";
But it both gave 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 'WHERE TAAK_ID='13'' at line 1
What might be the solution?
insert into syntax doesn't have where
INSERT INTO table_name
VALUES (value1,value2,value3,...);
probably you wanted to use insert into select
INSERT INTO table
( column name(s))
SELECT column name(s) from table where condition
OR
IF ( condition )
INSERT INTO table_name
VALUES (value1,value2,value3,...);

INSERT values from one table to another using SQL Query

I am trying to run this SQL Query:
INSERT INTO controldata (field,value)
VALUES (customer_billing_product_type,
SELECT name from customer_billing_product_types)
to insert all rows in the customer_billing_product_types table into the controldata table with the field always being customer_billing_product_type but i get an SQL Error saying:
#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
'SELECT name from customer_billing_product_types)' at line 1
The INSERT as you wrote it expects to insert one record, but then in values an entire set of records is returned. Try to change your query to
INSERT INTO controldata(field, value)
SELECT customer_billing_product_type, t.name FROM customer_billing_product_types t;
This selects all t.name values from customer_billing_product_types, adds customer_billing_product_type as column and inserts all the results into controldata.
You are using wrong syntax try below:
INSERT into controldata (field1) SELECT name from customer_billing_product_types;
If you want to keep a field as constant then you can use as per below:
INSERT into controldata (field,value) SELECT 'customer_billing_product_types',name from customer_billing_product_types;

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')

Error inserting data into mysql

I am trying to insert data from a csv file into mysql using BigDump.
It stops on line 2, with the error:
"Query: INSERT INTO location VALUES
(1,"O1","","","",0.0000,0.0000,, );
MySQL: 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 ' )' at line 1"
If I run the statement from withing phpmyadmin, it says:
"#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 ' )' at line 1"
What can I do to make the data get into the database?
Thank you.
The commas with no values looks sketchy to me.
INSERT INTO location VALUES (1,"O1","","","",0.0000,0.0000,, );
should probably be
INSERT INTO location VALUES (1,"O1","","","",0.0000,0.0000,NULL,
NULL);
Does your insert statement contain values for every column in the table? If not, you have to name the columns.
For example,
insert into location (col1, col2, col3) values (1, 2, 3);
If you show us the structure of the LOCATION table you can get better answers.