MySQL: INSERT INTO for each result

This MySQL query returns 900 results:
SELECT `ID` from `Member` WHERE `UserSuspended` = '1'

Open in new window

For each of those 900 results, I want to do this:
INSERT INTO `Group_Members` (`GroupID`,`MemberID`) VALUES ('18', '###  ID from the previous query ###')

Open in new window

LVL 16
Who is Participating?
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
run this as one statement:

INSERT INTO `Group_Members` (`GroupID`,`MemberID`) SELECT '18', `ID` from `Member` WHERE `UserSuspended` = '1'

Open in new window

hankknightAuthor Commented:
angelIII, that query does not work.  The problem is it is that "Select '18'" makes it return all results.

## Returns 100000 Results
SELECT '18', `ID` from `Member` WHERE `UserSuspended` = '1'

## Returns 900 Results
SELECT * from `Member` WHERE `UserSuspended` = '1'
Guy Hengel [angelIII / a3]Billing EngineerCommented:
adding another field into the query will not result in more or less records.
you must confuse things ...
difficult will be now to "see" what goes wrong in your case, I know for sure that INSERT ... SELECT ... works fine as such...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.