Reputation: 63
I have two tables LESSON & SPORT.
LESSONNO | SPORTNO | INSTRUCTORNO | DATE | PRICE |
SPORTNO | SPORT NAME | SPORTDESCRIPTION |
I need to add column SPORTNAME to the lesson table, and for its data to match the SPORTNO in lesson table as it does in sport table.
Thanks in advance!
Upvotes: 1
Views: 43
Reputation: 612
This worked for me in SQL Server
ALTER TABLE LESSON ADD SPORTNAME VARCHAR(50)
UPDATE LESSON
SET SPORTNAME = S.SPORTNAME
FROM dbo.LESSON AS L
INNER JOIN dbo.SPORT AS S
ON L.SPORTNO = S.SPORTNO
Hope it helps!
Upvotes: 1
Reputation: 5336
Does this work for you:
ALTER TABLE LESSON ADD SPORTNAME VARCHAR(30); // or whatever type it is
UPDATE LESSON l JOIN SPORT s USING(SPORTNO) SET l.SPORTNAME = s.SPORTNAME;
?
Upvotes: 1