Solved

MySQL: INSERT INTO for each result

Posted on 2011-09-05
3
313 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:hankknight
  • 2
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
run this as one statement:

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

Open in new window

0
 
LVL 16

Author Comment

by:hankknight
Comment Utility
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'
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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...
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now