0

So imagine i have two tables, Car and Driver, with respectively these structure :

(hash TEXT PRIMARY_KEY, brand TEXT, driver INTEGER)

and

(id INTEGER PRIMARY_KEY, name TEXT)

So now let's fill our table and imagine we insert into those table ("abcdefghi", "Honda",125) in Car and in Driver (125,"Marc").

What i'm looking for is an instruction that from Renault and Marc that updates effectively my table to transform ("abcdefghi", "Honda",125) into ("abcdefghi, "Renault",125).

4

2 に答える 2

1
UPDATE     Car
SET        brand = 'Renault'
FROM       Car c
INNER JOIN Driver d ON c.driver = d.id
WHERE      d.Name = 'Marc'

このコードを異なる値で頻繁に実行する予定がある場合は、'Renault' と 'Marc' を変数に変更することをお勧めします。

于 2012-08-07T13:10:37.937 に答える
0

これはあなたが探しているものですか?

update car
set
    brand = 'Renault'
from
    car
where 
    driver in (Select id from driver where name='Marc')
于 2012-08-07T13:07:08.830 に答える