大家好基本上我有一个查询,选择flagId = 6的所有clientId
是:
SELECT clientId from ClientsFlags WHERE flagId = 6;
现在我想从这个查询中获取结果,并为select语句中获得的每个结果创建一个新记录
INSERT INTO clientFlags clientId, flagId VALUES('The client ID's that were obtained in the select query', 42);
结合这些陈述的最佳方法是什么?
答案 0 :(得分:2)
INSERT INTO clientFlags (clientId, flagId)
SELECT clientId, 42
FROM ClientsFlags
WHERE flagId = 6;
像这样,我没有测试它的语法错误
答案 1 :(得分:0)
INSERT INTO clientFlags (SELECT clientId,42 from ClientsFlags WHERE flagId = 6)
答案 2 :(得分:0)
您的查询应该如下,
INSERT INTO clientFlags (clientId, flagId)
SELECT clientId, flagId
FROM ClientsFlags WHERE flagId = 6;
答案 3 :(得分:0)
INSERT INTO clientFlags (clientId, flagId) SELECT clientId, 42 from ClientsFlags WHERE flagId = 6;
答案 4 :(得分:0)
你可以像以下一样
INSERT INTO `clientFlags`
SELECT * FROM `clientFlags` WHERE `flagId` = 6
注意:此外,您必须记住,任何字段都不能是唯一字符或主键...