是否可以在“插入”查询中使用“select”查询,但条件是我想为“select”使用同一个表名并且“插入”查询。
例如mysql> insert into sample_elements (name,position,ownerel) values ('Namespace1', select id from sample_elements where name='Namespace1',0);
在插入查询中使用select查询获得相同的表名
请指导我这一点。基本上
insert into sample_elements (name,position,ownerel) select 'Namespace1',id,0 from sample_elements where name='Namespace1';
而不是使用值仅使用select语句并插入harcoded值列
-1此解决方案不适用于MySQL,OP明确使用该解决方案。看到这个答案:http://stackoverflow.com/a/14302701/998919 – fgblomqvist 2016-06-18 17:50:36
它在mySQL上工作,这就是我使用它的地方。请说明它在哪里/如何不起作用,因为我认为你会发现它的实现/版本/驱动程序是问题,而不是mySQL。问候 – 2016-06-20 09:47:27
我确实已经指定,检查我链接的答案。请至少说明您尝试过的MySQL数据库的版本。 – fgblomqvist 2016-06-20 15:10:02