我无法完成以下任务:
我有两张桌子:
User:
-uid
-username
challenge:
-cID
-challengerID
-challengedID
现在我想在insert into
应用中运行c#
(例如!挑战user1
user2
)
现在SQL
是:
insert into challenge (challengerID, challengedID)
where challengerID = id of user1 and challengedID = id of user2.
如何抓住这两个user IDs
并将它们存储在挑战表的不同字段中?
答案 0 :(得分:4)
使用join
:
insert into challenge (challengerID, challengedID)
select u1.id, u2.id
from users u1 join
users u2
on u1.username = 'user1' and u2.username = 'user2';
编写查询时,应使用名称参数。不要使用名称来查询查询字符串。