Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update a column based on a field from another table

Tags:

sql

sqlite

I'd like to update values in one table based on corresponding values from other tables. Say you want to update prices of pieces provided by one specific manufacturer whose name is in the table Manufacturers with the Pieces table containing only the id of the manufacturer.

I've seen several solutions for MySQL here and for MS SQL Server here but none of them seems to work in SQLite.

Any suggestion?

like image 269
Sergio Avatar asked May 17 '10 23:05

Sergio


1 Answers

Have you tried something like this?

UPDATE Pieces
SET price = 42
WHERE manufacturer_id = (
    SELECT id
    FROM Manufacturers
    WHERE Name = 'FooBar Inc.'
)
like image 139
Mark Byers Avatar answered Sep 25 '22 16:09

Mark Byers