我在完成以下任务时遇到困难:
我有 2 张 table :
User:
-uid
-username
challenge:
-cID
-challengerID
-challengedID
现在我想从 c#
应用程序运行 insert into
(例如!challenge user1
user2
)
现在SQL
是:
insert into challenge (challengerID, challengedID)
where challengerID = id of user1 and challengedID = id of user2.
如何获取这两个用户 ID
并将它们存储在挑战表的不同字段中?
最佳答案
使用加入
:
insert into challenge (challengerID, challengedID)
select u1.id, u2.id
from users u1 join
users u2
on u1.username = 'user1' and u2.username = 'user2';
编写查询时,应使用名称参数。不要将查询字符串与名称混在一起。
关于c# - SQL选择两个userID作为不同的别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45870665/