My question is related to the answer found in this post by user Consultuning on Oct 22 '09 at 18:31: mysql query to dynamically convert row data to columns
It appears that Consultuning's answer contains some MySQL with a For Each row
loop.
Can you do a For Each Row
loop using MySQL?
If so, could someone give me a link to the MySQL For Each Row
documentation?
foreach() acts on server side only, and does not require shell access nor the mysql command line client, although it may be spawned from within the mysql client. foreach() accepts several types of collections. They are automatically recognized by their pattern.
You can use these statements in the stored programs (procedures), and RETURN in stored functions. You can use one Flow Control Statement with in another. The ITERATE statement is used to restart the LOOP, REPEAT or, WHILE statements. It cannot be used outside these statements.
The MySQL LOOP statement could be used to run a block of code or set of statements, again and again, depends on the condition. labelname : It is an optional label at the start and end. statements : They could have one or multiple statements, each ended by a semicolon (;) and executed by LOOP.
The MySQL stored program language offers three types of loops : Simple loops using the LOOP and END LOOP clauses. Loops that continue while a condition is true, using the WHILE and END WHILE clauses. Loops that continue until a condition is true, using the REPEAT and UNTIL clauses.
The closest thing to "for each" is probably MySQL Procedure using Cursor and LOOP.
Not a for each exactly, but you can do nested SQL
SELECT
distinct a.ID,
a.col2,
(SELECT
SUM(b.size)
FROM
tableb b
WHERE
b.id = a.col3)
FROM
tablea a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With