phpmyadmin update query using 3 tables in giving error - mysql

I am getting the following Error
064 - 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 catalog_product_flat_1 a inner join
catalog_product_entity c on a.sku' at line 3
when I try out the below query on phpmyadmin
update a
set a.small_image = b.value
from `catalog_product_flat_1` a
inner join `catalog_product_entity` c
on a.sku = c.sku
inner join `catalog_product_entity_media_gallery` b
on b.entity_id = c.entity_id
I also tryout without using alias but still same issue

The SET clause comes after the JOIN clauses:
UPDATE `catalog_product_flat_1` a
inner join `catalog_product_entity` c
on a.sku = c.sku
inner join `catalog_product_entity_media_gallery` b
on b.entity_id = c.entity_id
SET a.small_image = b.value
See the documenation:
http://dev.mysql.com/doc/refman/5.5/en/update.html

Related

Update and select query in mysql query

I am using the below format to use select and update command in the same query.
UPDATE t
SET t.col1 = o.col1
FROM table1 AS t
INNER JOIN
table2 AS o
ON t.id = o.id
I applied the same concept in my query but it is throwing an error which I am not able resolve. Any idea where I am going wrong here?
update T set T.price = 2*OT.ingredients from Cake as T Inner join (select
A.cakeid, B.price, sum(C.price) ingredients
from
Contain as A
inner join
Cake as B ON A.cakeid = B.cakeid
inner join
Ingredient as C ON C.ingredid = A.ingredid
group by A.cakeid
having B.price <= 2 * sum(C.price) ) as OT on OT.cakeid = T.cakeid
Error Code: 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 Cake as T Inner join (select A.cakeid, B.price, sum(C.price) ingredien' at line 1
The correct syntax in MySQL is:
update Cake T Inner join
(select A.cakeid, B.price, sum(C.price) ingredients
from Contain A inner join
Cake B
ON A.cakeid = B.cakeid inner join
Ingredient as C
ON C.ingredid = A.ingredid
group by A.cakeid
having B.price <= 2 * sum(C.price)
) OT
on OT.cakeid = T.cakeid
set T.price = 2*OT.ingredients ;

Update a table by joining 3 tables

i have 3 tables:
tblproduct (pro_Id, qty, unitprice)
tblorderdetails (order_id, pro_Id, qty)
tblorder (order_id, totalAmount)
i intend joining these tables to as to update the totalAmount in the tblorder table. This is my query using MySql console:
UPDATE o
SET o.totalAmount = p.unitprice * d.qty
FROM tblorder o INNER JOIN tblorderdetails d
on o.order_id = d.order_id
INNER JOIN tblproduct p
on p.pro_Id = d.pro_Id;
This is the error i get:
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 'from tblorder o inner join tblorderdetails d
The syntax is not correct and it should be as
UPDATE tblorder o
INNER JOIN tblorderdetails d
on o.order_id = d.order_id
INNER JOIN tblproduct p
on p.pro_Id = d.pro_Id
SET o.totalAmount = p.unitprice * d.qty ;

MYSQL query using Left Join and Where IN clause

I have three tables A B C and i'm trying to retrieve information from all three.
A has the columnns userid avatar username and B has the column postid, dateshared and C has the column commenter postid datecommented.
I'm trying to run the query
Select C.comment, C.commenter, C.datecommented, B.postid, B.dateshared A.username A.avatar from B Left Join C Left join A on C.postid = B.postid AND A.userid = C.commenter where B.postid IN ('1','2','3') order by C.dateshared desc
but it gives 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 'where B.postid IN ('1', '2', '3') order by C.dateshared '
Can anyone point out what I'm doing wrong or suggest how to go about it?
Each LEFT JOIN requires its own ON condition:
SELECT C.comment, C.commenter, C.datecommented, B.postid, B.dateshared, A.username A.avatar
FROM B
LEFT JOIN
C
ON C.postid = B.postid
LEFT JOIN
A
ON A.userid = C.commenter
WHERE B.postid IN ('1','2','3')
ORDER BY
C.dateshared desc
This should work for you, your query had some syntax errors:
Select C.comment,C.commenter,C.datecommented,B.postid,B.dateshared,A.username,A.avatar
from B
Left Join C on C.postid = B.postid
Left join A on A.userid = C.commenter
where B.postid IN ('1','2','3')
order by C.dateshared desc

MySQL OUTER JOIN syntax error

Maybe a facepalm for you guys, but as a SQL query newbie, I'm having a syntax issue. Anyone know what's wrong?
SELECT * FROM company C
OUTER JOIN company_address A ON C.company_id = A.company_id
WHERE A.company_id IS NULL
Giving 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
'OUTER JOIN company_address A ON C.company_id = A.company_id WHERE A.address_id
' at line 2
In MySQL you should use LEFT OUTER JOIN or RIGHT OUTER JOIN. There is no just OUTER JOIN. If you need FULL OUTER JOIN in MySql you can use UNION of LEFT JOIN and RIGHT JOIN
Try
SELECT * FROM company C
LEFT JOIN company_address A ON C.company_id = A.company_id
WHERE A.company_id IS NULL
You have to write LEFT JOIN,RIGHT JOIN,INNER JOIN or FULL OUTER JOIN instead of only OUTER JOIN.
There is also one error with your table name there shouldn't be space between the letters of a table like this [company C- it should be named as company_C]
I hope that will be work..All the best!

mysql error inner join

I used a query like
select a.email,b.vuid
from user a
,inner join group b on a.uid = b.uid
where a.email='xx#xx.de' and a.kid=1 and b.vid=29
limit 1
but I always get 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 'inner join group b on a.uid = b.uid where a.email='xx#xx.de' at line 1
I think its because the inner join but I don't know really.. Could someone help me?
Remove the , after from user a.
Your query should be:
select a.email,b.vuid
from user a
inner join group b
on a.uid = b.uid
where a.email='xx#xx.de'
and a.kid=1
and b.vid=29
limit 1
select a.email,b.vuid from user as a inner join group as b on ...
Of course you can omit the as keyword as demonstrated by #FrustratedWithFormsDesigner but in my opinion it is much more readable this way.