0

Here is my problem.I have two tables Stdd and result.

stdd columns:

id
fname
lname
gender
phonenum
city

result columns:

physics
chem
math
english
urdu
bio
total
id

I want that in result table the column id copy data from stdd column id, and other columns of result columns remain empty or null.

How can i do this please help. I try this but nor works for me

       update result set  id= (select id from stdd)

following error come

Msg 512, Level 16, State 1, Line 1 Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. The statement has been terminated.

I want this kind of output.Here is 'result' table link

I'm using microsoft sql server 2008

  • Does it must be an Update or could it be an Insert, too? – Niklas B. Jan 11 '16 at 8:58
1

You could use INSERT with a SELECT.

INSERT INTO result (id) SELECT id FROM stdd

With this your SQL Server adds per row in stdd one row in result with the id from stdd.

If you can use multiple columns, too.

INSERT INTO result (id, col2, col3) SELECT id, s_col2, s_col3 FROM stdd

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.