我已经尝试过,但出现错误:
在此上下文消息中不允许出现SubQuery。
我有两个表Product
和Category
,并且要基于categoryId
使用CategoryName
。
查询是
Insert into Product(Product_Name,Product_Model,Price,Category_id)
values(' P1','M1' , 100, (select CategoryID from Category where Category_Name=Laptop))
请告诉我一个带有代码的解决方案。
最佳答案
这样尝试
Insert into Product
(
Product_Name,
Product_Model,
Price,Category_id
)
Select
'P1',
'M1' ,
100,
CategoryID
From
Category
where Category_Name='Laptop'
关于c# - 如何在插入语句中使用子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20771820/