2009-02-26 7 views

Répondre

2

Essayez quelque chose comme ceci:

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 ('', '', ''); 
1
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 ('', '', '') 
0
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 ('', '', '') 
0
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 ('','','') 
0

Je crois en MS SQL Server (mais pas Oracle), vous pouvez écrire:

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 ('', '', '') 
0
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 
5

Je commencerais par convertir à l'aide rejoint au lieu de « classique rejoindre »:

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 ('', '', '') 

Ensuite, vous pouvez simplement extraire de l'instruction select et gifler une mise à jour et déclaration qui figure sur elle:

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 ('', '', '') 
+0

+1 pour expliquer processus de pensée. – sfossen

0
update t1 set t1.status=(select 1 from Table1 t1, Table2 t2, Table3 t3 WHERE t2.ID = t3.ID AND t1.ID = t2.ID AND t3.Guid IN ('', '', '')) 
Questions connexes