Link to home
Start Free TrialLog in
Avatar of mainrotor

asked on

I need help with a SQL Query

Hi Experts,
I need help with an update query between 2 tables without using a from/join clause.
How can I do this.

Thanks in advance,
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

You can do that by giving us table names, field names to be updated, etc. Any relevant information we need to built a workable example.

Also see:
Here is one example
UPDATE Test1.dbo.Employee
SET DeptID = emp2.DeptID
FROM Test2.dbo.Employee as 'emp2'
   Test1.dbo.Employee.EmployeeID = emp2.EmployeeID

Open in new window

Avatar of Qlemo
If two tables are involved, you cannot go without a FROM clause. Anything using a different source than the  table to update requires it. With one exception: You can build an updatable view, which obfuscates the table the column is located in - but that has a lot of constraints, and I won't go into the details for that reason.

If you are trying to head towards something e.g. Oracle allows, which is
update (select ta.ca1, tb.cb2 from table1 ta join table2 tb on = /* ... */)
set ca1 = cb2

Open in new window

this cannot be used in MSSQL that way, and anyway it contains a FROM too :D
Avatar of awking00
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial