[英]Using the result of a SELECT query as a value in an INSERT query
Is it possible to use the result of query as the value of a field in an INSERT query? 是否可以将查询结果用作INSERT查询中的字段值? This is what I'd like to achieve but am I going about it the right way? 这是我想要实现的目标,但是我会以正确的方式进行吗?
INSERT INTO tblCounts ( CategoryID, GroupID, CountNo )
VALUES (DMAX("CategoryID","tblCategories"), (SELECT GroupID from tblGroups), 0);
You should use this: 您应该使用此:
INSERT INTO tblCounts ( CategoryID, GroupID, CountNo )
select DMAX("CategoryID","tblCategories"), GroupID, 0
from tblGroups;
But it seem that DMAX
is Access function
, not MySQL
? 但是似乎DMAX
是Access function
,不是MySQL
吗?
For condition with a CountNo of 3 and CategoryID of 2 you should add where clause to the select query like this: 对于CountNo为3且CategoryID为2的条件,应将where子句添加到select查询中,如下所示:
INSERT INTO tblCounts ( CategoryID, GroupID, CountNo )
select DMAX("CategoryID","tblCategories"), GroupID, 0 -- select 2, GroupID, 3 from tblgroups where CategoryID = 2 and CountNo = 3--?
from tblGroups
where CategoryID = 2 and CountNo = 3;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.