P. Grunder P. Grunder - 6 months ago 20
SQL Question

SQL Update across Two different Tables in Microsoft Server Management Studio

Im new kind of new to SQL and im trying to get an update query across Two Tables. Specificly i got those two tables:

PERSON (name, surname, email, phone, adress_id, room_id)


and

ROOM (room_id, number_of_beds, house_id)


and i would like to update the person on room_id. I thought of a statement like:

UPDATE PERSON
SET room_id = room_id
FROM ROOM
INNER JOIN ROOM ON
room_id = room_id


My friend told me to use aliases for a better overview but i don't understand how to use those.

Would this statement work and how could i use aliases in the statement?

Answer
update p--is an alias to person
set 
p.stuffyouwantset=r.stuffyouwant
from 
person p
join
room r
on p.room_id=r.room_id