Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server query - how to insert selected values into another table

Here's what I am trying to do.

This is the select statement

select Id 
from tblUsersPokemons 
where UserId = 1 and PokemonPlace = 'bag'

Now I want to insert those returned Ids into another table like this:

foreach all returned Ids
   insert into tblNpcBattleUsersPokemons values (Id, 1)

How can I do that ?

like image 721
MonsterMMORPG Avatar asked Dec 04 '22 01:12

MonsterMMORPG


1 Answers

Like this:

insert into tblNpcBattleUsersPokemons
select Id, 1 from tblUsersPokemons where UserId=1 and PokemonPlace='bag'
like image 180
RBarryYoung Avatar answered Jan 22 '23 09:01

RBarryYoung