0

I am having a User table in which some records are available.
enter image description here

I want to select Id3 with this condition id<5 and insert 4 new rows in the User table with Id2=10000 a constant value
For example: consider row 1 which is having id=1,id2=200, and Id3=300, I want to insert a new record where Id2=10000 and Id3=300

Is there any way to avoid writing 4 insert statements manually. Please suggest to me.

1

1 Answer 1

1

Consider the insert ... select syntax:

insert into users (id, id2, id3)
select id, 200, id3
from users
where id <= 100

If would probably be safer to not take in account rows that already have id2 set to 200:

insert into users (id, id2, id3)
select id, 200, id3
from users
where id <= 100 and id2 <> 200
Sign up to request clarification or add additional context in comments.

1 Comment

I think the OQ wants to insert many rows in one of his scenarios.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.