Update Subquery

G

Guest

Is it possible to run an update statement with a subquery? What is the syntax?

Say you have emp and dept tables.

update emp set emp.depdesc = select dept.description from dept where emp.deptno
= dept.deptno

In other words I want to put values in preexisting records based on another
table. If dept has a description, then I want emp to have fname, lname, deptno,
deptdescription.

Is that possible?




(e-mail address removed)
 
G

Gerald Stanley

The proper syntax for
update emp set emp.depdesc = select dept.description from
dept where emp.deptno
= dept.deptno
is
UPDATE emp INNER JOIN dept ON emp.deptno = dept.deptno SET
emp.depdesc = dept.description

Hope This Helps
Gerald Stanley MCSD
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top