Solved

MySQL: INSERT INTO for each result

Posted on 2011-09-05
3
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 36484616
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
ID: 36484997
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 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 36485029
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

691 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