我正在尝试在 MS SQL 2012 Express 上运行以下查询:
Select (
Select Id, Salt, Password, BannedEndDate
from Users
where username = '" + LoginModel.Username + "'
), (
Select Count(*)
From LoginFails
where username = '" + LoginModel.Username + "'
And IP = '" + Request.ServerVariables["REMOTE_ADDR"] + "')"
);
但是我收到以下错误:
Only one expression can be specified in the
select
list when the subquery is not introduced withEXISTS
.
如何解决这个问题?
最佳答案
试试这个:
Select
Id,
Salt,
Password,
BannedEndDate,
(Select Count(*)
From LoginFails
Where username = '" + LoginModel.Username + "' And IP = '" + Request.ServerVariables["REMOTE_ADDR"] + "')
From Users
Where username = '" + LoginModel.Username + "'
并且我强烈建议您在查询中使用参数,以避免 SQL 注入(inject)攻击的安全风险!
希望有帮助!
关于sql - 如何修复 "Only one expression can be specified in the select list when the subquery is not introduced with EXISTS"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17403475/