Reputation: 39
I have 2 tables with the following fields.
Person: IDNumber, Name
Summary: IDNumber, Sports
I would like to copy Person.IDNumber to Summary Table and at the same time set Sports to Running assuming all the people's favourite sport is Running, doing the copying of column and setting the value to Running at the same time. I am able to copy the whole column of Person.IDNumber to Summary.IDNumber, but how do i go about setting the value to Running for Summary.Sports?
Insert into Summary(IDNumber)
select IDNumber from Person
How should I go about doing it?
Upvotes: 1
Views: 45
Reputation: 97101
You can use a field expression to give you the value "Running" for every row of your Person
table.
SELECT IDNumber, 'Running' AS Sports FROM Person
Then you can insert that result set into your Summary
table.
INSERT INTO Summary(IDNumber, Sports)
SELECT IDNumber, 'Running' AS Sports FROM Person
Upvotes: 2