1

次のクエリを実行しようとしています。

update table3 d set status = 'Complete'
where d.id in 
(
    select b.id from table1 a, table3 b, table2 c
    where a.id = b.table1_id
    and c.id = b.table2_id
    and c.examId = 16637                 -- will be passed in by user
    and a.id in (46,47,48,49)            -- will be passed in by user
);

だから、私はの複数の行を更新しようとしていますtable3

table3table1との間の結合テーブルtable2です。

4

1 に答える 1

3

サブクエリでラップします(したがって、結果の一時テーブルを作成します)。フォーマットの使用もお勧めしANSI SQL-92ます。

update table3 d 
set    status = 'Complete'
where  d.id in 
(
    SELECT ID
    FROM
    (
        select  b.id 
        from    table1 a 
                INNER JOIN table3 b
                    ON a.id = b.table1_id
                INNER JOIN table2 c
                    ON c.id = b.table2_id
        where   c.examId = 16637 and 
                a.id in (46,47,48,49) 
    ) xx
);

またはを使用してJOIN

update  table3 d 
        INNER JOIN
        (
            SELECT ID
            FROM
            (
                select  b.id 
                from    table1 a 
                        INNER JOIN table3 b
                            ON a.id = b.table1_id
                        INNER JOIN table2 c
                            ON c.id = b.table2_id
                where   c.examId = 16637 and 
                        a.id in (46,47,48,49) 
            ) xx
        ) y ON d.id = y.id
set status = 'Complete'
于 2012-11-02T02:49:28.197 に答える