Reputation: 703
Trying to insert a new row for each of the entries of a table.
INSERT INTO `serviceProducts`(`model_id`, `url_name`, `priority`, `status`, `info`, `image_link`, `mobilephone`, `service`, `time`, `price`)
SELECT id FROM models,
CONCAT(SELECT url_name FROM models,"-felsoekning"),
10,
1,
"",
"",
(SELECT name FROM models),
"Felsökning",
"",
399
I want to add a new "service" entry for each of the models present. Therefore I need to select all model ids as well as their url-friendly names and normal names. This query returns an error near (SELECT name FROM models).
Upvotes: 1
Views: 1406
Reputation: 782364
Don't use subqueries in the SELECT
. Just use a single SELECT
that merges the constants with the columns from the other table.
INSERT INTO `serviceProducts`(`model_id`, `url_name`, `priority`, `status`, `info`, `image_link`, `mobilephone`, `service`, `time`, `price`)
SELECT id, CONCAT(url_name,"-felsoekning"), 10, 1, "", "", name, "Felsökning", "", 399
FROM models
Upvotes: 1
Reputation: 7469
What about
INSERT INTO `serviceProducts`(`model_id`, `url_name`, `priority`, `status`, `info`, `image_link`, `mobilephone`, `service`, `time`, `price`)
SELECT id,
CONCAT(url_name, "-felsoekning"),
10,
1,
"",
"",
name,
"Felsökning",
"",
399
from models;
Upvotes: 2