SQL syntax error adding data opencart DB - mysql

Im looking to add all products that dont have attribute_id = 12 into oc_product_attribute,
But getting a syntax 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 '12) select ocp.product_id from oc_product ocp where ocp.product_id not in (SE' at line 1
insert into `oc_product_attribute` (ocp.product_id, 12)
select ocp.product_id from oc_product ocp where ocp.product_id not in (SELECT oca.`product_id`
FROM `oc_product_attribute` oca where oca.attribute_id = 12)
Am I missing something here, quite new to SQL.

Usually you have to enumerate columns in insert statements.
insert into `oc_product_attribute` (ocp.product_id, 12)
must be
insert into `oc_product_attribute` (ocp.product_id, some_column_name)
and I guess it may be attribute_id.
For more details, please see the reference manual -> http://dev.mysql.com/doc/refman/5.6/en/insert-select.html

Related

What is wrong with this MySQL command?

The query that is throwing an error for my MySQL DB is:
SELECT t1.GROUPNAME FROM user_group t0, group t1 WHERE ((t0.users_USERNAME =
?) AND (t1.GROUPNAME = t0.groups_GROUPNAME))
The error info is the following:
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 'group t1 WHERE
((t0.users_USERNAME = 'test') AND (t1.GROUPNAME = t0.groups_GROUP')
Okay so I know the problem is with the group t1 part. But I dont know what is wrong with it.
Click here to see that I have all the needed colums
Can any one find out what the problem could be here?
group is a reserved word in SQL. You should put quotes around it.
Some JPA providers do that automatically, whereas others don't ...

MySQL syntax error when using sqlite3 query

I just wanted to switch from sqlite3 to using MySQL but I get errors in this query:
SELECT
metapp_notif.id,
name,
age,
place,
note,
metapp_notif.lat,
metapp_notif.longt,
haslatlong,
dati,
ntype,
grpm_id,
image,
send_id,
pro.latitude,
pro.longtitude,
metapp_notif.dati,
metapp_notif.activity
FROM (metapp_notif
join (metapp_profil
join metapp_userlocation
ON metapp_profil.user_id = metapp_userlocation.user_id) AS pro
ON metapp_notif.send_id = pro.user_id)
WHERE metapp_notif.rec_id =% d;
I'm getting this error:
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 'pro on metapp_notif.send_id=pro.user_id) where
metapp_notif.rec_id=2' at line 1
I was searching for differences between sqlite3 and mysql but can't figure out what is wrong.
Thanks in advance!
Try this syntax in Mysql
SELECT metapp_notif.id,
name,
age,
place,
note,
metapp_notif.lat,
metapp_notif.longt,
haslatlong,
dati,
ntype,
grpm_id,
image,
send_id,
latitude,
longtitude,
metapp_notif.dati,
metapp_notif.activity
FROM metapp_profil
join metapp_notif
ON metapp_notif.send_id = metapp_profil.user_id
join metapp_userlocation
ON metapp_profil.user_id = metapp_userlocation.user_id
WHERE metapp_notif.rec_id like '% d'; -- Not sure what you are trying to do here

SQL execution error

I try this query
INSERT INTO shop.product(prod_id,model,desc) SELECT product.id_prod,prod_lang.name,product.ref from product left join product_lang on product_lang.id_prod = product.id_prod
However I got this error
SQL execution error # 1065.Response from the database:
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 product.id_prod,product_lang.name,product.ref from' at line 1
Two problems:
DESC is a reserved keyword. Use backquote (``) for desc.
Change prod_lang to product_lang in the query.
Solution:
INSERT INTO shop.product (prod_id,model,`desc`)
SELECT product.id_prod,product_lang.name,product.ref
from product left join
product_lang on product_lang.id_prod = product.id_prod
Note:
It is a good practice to use backquotes for all columns eventhough it is not a reserved keyword.

what is wrong following mysql query?

INSERT INTO lm_empleavetypemodelmap(leavetypeid,userid)
VALUES(1682,"b0c6c81f-a20a-4daa-9038-831478d8e11b")
WHERE lm_empleavetypemodelmap.userid NOT IN
(SELECT lm_empleavetypemodelmap.userid
FROM lm_empleavetypemodelmap
WHERE lm_empleavetypemodelmap.leavetypeid = 1683)
[Err] 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 lm_empleavetypemodelmap.userid NOT IN( select lm_empleavetypemodelmap.user' at line 1
You do not use where with values. Perhaps the stuff at the end is just accidental garbage and you just want:
INSERT INTO lm_empleavetypemodelmap(leavetypeid, userid)
SELECT 1682, 'b0c6c81f-a20a-4daa-9038-831478d8e11b';
Or, in what looks rather strange to me:
INSERT INTO lm_empleavetypemodelmap(leavetypeid, userid)
SELECT 1682, 'b0c6c81f-a20a-4daa-9038-831478d8e11b'
WHERE NOT EXISTS (SELECT 1 FROM lm_empleavetypemodelmap WHERE leavetypeid = 1683)
That is, insert 1682, if 1683 doesn't exist. Usually you care about the value being inserted, not the next value.

#1064 - You have an error in your SQL syntax when creating a View

Could someone please tell me what's wrong with this code that's making it spit back an error?
My code is as follows:
CREATE OR REPLACE VIEW vw_training AS
SELECT training.train_attended, clients.client_firstname, clients.client_lastname, clients.client_swn, clients.client_id, locations.loc_id, locations.loc_title, locationsp.loc_id, locationsp.loc_title,
FROM training
JOIN clients ON clients.client_id = training.train_clientid
JOIN locations AS locationsp ON locations.loc_id = training.train_pickup
LEFT JOIN locations ON locations.loc_id = clients.client_winz
And this is the error I'm getting back:
#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 'FROM training JOIN clients ON clients.client_id =
training.train_clientid JOIN' at line 3
I'm running phpmyadmin Version information: 3.5.2.2
I've used this script with different values before with no issues
You have an extra trailing comma before the FROM clause
SELECT ....,
locationsp.loc_id,
locationsp.loc_title, -- <<== remove this trailing comma
FROM training ...
and another error that will raise this message: Unknown column 'locations.loc_id' in 'on clause' is the use of tablename and not the alias supplied. it should be,
JOIN locations AS locationsp ON locationsp.loc_id = training.train_pickup
^^ should use alias here