Looping through results

Can’t seem to find the answer to this anywhere.

How can I do this type of query in MySQL…

SELECT a, b, c FROM table;

for each result returned {
if a = 1 then ( insert into table2 (a) values (a) )
else then ( insert into table3 (a) values (a) )
}

The INSERT INTO SELECT syntax will do it…You’d just need two, one where a = 1, and one where it doesn’t.

INSERT INTO table2 (col1, col2, ..., colN)
SELECT col1, col2, ..., colN
  FROM table1
 WHERE col2 = 'x';

That was just a high-level example of what I am trying to do :stuck_out_tongue:

And I was just giving you a high level example on how to handle it without a loop :wink:

Haha, that product hierarchy is driving me mad.

I think I’m going to have to give up and ask someone on fiverr to do it :frowning:

[drops mic]

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.