J
J
jtag2017-10-23 15:21:48
MySQL
jtag, 2017-10-23 15:21:48

To form a long query in the database?

DB - MySQL. Hundreds of rows need to be inserted in a single query, and the third parameter must be taken from an adjacent table. How to generate a query through a loop?
var sql = "INSERT INTO person (id, name, school) VALUES (?, ?, (SELECT id FROM school WHERE number='?'))";

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2017-10-23
@BorisKorobkov

INSERT INTO person (id, name, school) 
SELECT id, ... AS name, ... AS school FROM school WHERE ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question