2

I have a table of people that is populated with all the MLB players (mostly contiguous by team), coaches and refs, as follows:

+-----------+-------------+------+-----+---------+----------------+
| Field     | Type        | Null | Key | Default | Extra          |
+-----------+-------------+------+-----+---------+----------------+
| id        | int(11)     | NO   | PRI | NULL    | auto_increment |
| firstname | varchar(30) | NO   |     | NULL    |                |
| lastname  | varchar(30) | NO   |     | NULL    |                |
+-----------+-------------+------+-----+---------+----------------+

as well as a players table, which is empty, but described as follows:

+-----------+---------+------+-----+---------+----------------+
| Field     | Type    | Null | Key | Default | Extra          |
+-----------+---------+------+-----+---------+----------------+
| id        | int(11) | NO   | PRI | NULL    | auto_increment |
| person_id | int(11) | NO   | MUL | NULL    |                |
| team_id   | int(11) | NO   | MUL | NULL    |                |
+-----------+---------+------+-----+---------+----------------+

And I want to be able to loop through the players table and add in a range of person_ids and team_ids like this:

for(int x=100; x < 140; x++)
   insert into player values (NULL, x, 6)

but I know I can't mix and match languages like that, so how can I accomplish this? And if you need any further information just ask.

1 Answer 1

4
insert into players( person_id, team_id ) as
select id, 6 
from my_first_table
where id >= 100
and id < 140
Sign up to request clarification or add additional context in comments.

Comments

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.