Reise45
Reise45

Reputation: 1203

sql update column value using result in another table

I have a table T1

Fruit | Quantity
----------------
Apple | 2
Grape | 3

I have table T2

Factor
------
  2

I want final result

Fruit | Quantity
----------------
Apple | 4
Grape | 6

A little confused how to do an update since my second table doesn't have any id's I can join on. I am using RedShift.

Upvotes: 0

Views: 817

Answers (2)

Juan Carlos Oropeza
Juan Carlos Oropeza

Reputation: 48177

UPDATE T1
SET Quantity = Quantity * T2.factor
FROM T2

-- optional
WHERE T1.id = T2.id

see working sqlFiddle

Upvotes: 0

juergen d
juergen d

Reputation: 204746

select t1.fruit, t1.quantity * t2.factor
from t1
cross join t2

Upvotes: 1

Related Questions