using a JOIN in an UPDATE in SQL
Posted
by SDLFunTimes
on Stack Overflow
See other posts from Stack Overflow
or by SDLFunTimes
Published on 2010-04-28T03:06:49Z
Indexed on
2010/04/28
3:13 UTC
Read the original article
Hit count: 377
Hi, I'm having trouble formulating a legal statement to double the statuses of the suppliers (s) who have shipped (sp) more than 500 units. I've been trying:
update s
set s.status = s.status * 2
from s join sp
on (sp.sno = s.sno)
group by sno
having sum(qty) > 500;
however I'm getting this error from Mysql:
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 s join sp on (sp.sno = s.sno) group by sno having sum(qty) > 500' at line 1
Does anyone have any ideas about what is wrong with this query? Here's my schema:
create table s
( sno char(5) not null,
sname char(20) not null,
status smallint,
city char(15),
primary key (sno)
);
create table p
( pno char(6) not null,
pname char(20) not null,
color char(6),
weight smallint,
city char(15),
primary key (pno)
);
create table sp
( sno char(5) not null,
pno char(6) not null,
qty integer not null,
primary key (sno, pno)
);
© Stack Overflow or respective owner