Link to home
Start Free TrialLog in
Avatar of mainrotor
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,
mrotor
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: https://www.experts-exchange.com/articles/18499/Top-10-Ways-to-Ask-Better-Questions.html
Here is one example
UPDATE Test1.dbo.Employee
SET DeptID = emp2.DeptID
FROM Test2.dbo.Employee as 'emp2'
WHERE
   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 ta.id = tb.id /* ... */)
set ca1 = cb2

Open in new window

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

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