Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to insert as much values into another table as it's definied in a specific colum from other table
    text
    copied!<p>I have two tables, Movements and sales</p> <p><strong>Movements</strong> (example)</p> <pre><code>clock_model| piece_ref| original_stock | -----------+----------+----------------- R0000000000| 0000ZZZ | 5 | </code></pre> <p><strong>Sales</strong> (I just show you the structure)</p> <pre><code>id_sale (autoincrement numeric value) piece_ref pieces_to_sent type_of_sale customer lastupdate_date lastupdate_by </code></pre> <p>I would like to know which query should be the right one to insert as many piece_ref into sales table as its result would be something like this from the example above:</p> <p><strong>Sales</strong></p> <pre><code>id_sale| piece_ref| pieces_to_sent | type_of_sale | customer | lastupdate_date -------+----------+-----------------+--------------+----------+----------------- 1 | 0000ZZZ | 0 | "none" | "no one" | NOW() 2 | 0000ZZZ | 0 | "none" | "no one" | NOW() 3 | 0000ZZZ | 0 | "none" | "no one" | NOW() 4 | 0000ZZZ | 0 | "none" | "no one" | NOW() 5 | 0000ZZZ | 0 | "none" | "no one" | NOW() </code></pre> <p>I think that the postgresql query would be something like this:</p> <pre><code>INSERT INTO `Sales` (`piece_ref`, `pieces_to_sent `, `type_of_sale`, `customer`,`lastupdate_date`) SELECT `Movements`.`piece_ref`, 0, "", "", NOW(), "admin" FROM `Movements`, generate_series(1, `Movements`.original_stock) AS rn </code></pre> <p>But as you know generate_series function doesn't exists in MySQL. Could you please provide me some help on this?</p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload