SELECT t1.status, t3.guid, t3.objectID
FROM Table1 t1, Table2 t2, Table3 t3
WHERE t2.ID = t3.ID
AND t1.ID = t2.ID
AND t3.Guid IN ('', '', '')
How can I convert this to an update statement where I set the t1.status = 1
?
SELECT t1.status, t3.guid, t3.objectID
FROM Table1 t1, Table2 t2, Table3 t3
WHERE t2.ID = t3.ID
AND t1.ID = t2.ID
AND t3.Guid IN ('', '', '')
How can I convert this to an update statement where I set the t1.status = 1
?
Try something like this:
update Table1
set status = 1
from Table1 t1
inner join Table2 t2 on t1.ID = t2.ID
inner join Table3 t3 on t2.ID = t3.ID
where t3.Guid IN ('', '', '');
UPDATE Table1
SET status = 1
FROM Table1 t1, Table2 t2, Table3 t3
WHERE t2.ID = t3.ID
AND t1.ID = t2.ID
AND t3.Guid IN ('', '', '')
update Table1
set status = 1
FROM Table1 t1, Table2 t2, Table3 t3
WHERE t2.ID = t3.ID
AND t1.ID = t2.ID
AND t3.Guid IN ('', '', '')
UPDATE Table1 set status = 1
from table2 t2, table 3 t3
where t2.ID = t3.ID
and Table1.ID = t2.ID
and t3.GUID in ('','','')
I believe in MS SQL Server (but not Oracle), you can write:
UPDATE TABLE1
set t1.status = 1
FROM Table1 t1, Table2 t2, Table3 t3
WHERE t2.ID = t3.ID
AND t1.ID = t2.ID
AND t3.Guid IN ('', '', '')
MERGE
INTO Table1 t1
USING
(
SELECT t2.id
FROM Table2 t2, Table3 t3
WHERE
t3.ID = t2.id
AND t3.GUID IN ('', '', '')
) to
ON t1.id = to.id
WHEN MATCHED THEN
UPDATE
SET t1.status = 1
I would start by converting it to using joins instead of "classical joining":
select t1.status, t3.guid, t3.objectID
from Table1 t1
inner join Table2 t2 on t2.ID = t1.ID
inner join Table3 t3 on t3.ID = t2.ID
where t3.Guid in ('', '', '')
Then you can just rip of the select statement and slap an update and set statement on it:
update t1
set status = 1
from Table1 t1
inner join Table2 t2 on t2.ID = t1.ID
inner join Table3 t3 on t3.ID = t2.ID
where t3.Guid in ('', '', '')