如何修复“当子查询未与EXISTS一起引入时,只能在选择列表中指定一个表达式".错误? [英] How to fix "Only one expression can be specified in the select list when the subquery is not introduced with EXISTS" error?
本文介绍了如何修复“当子查询未与EXISTS一起引入时,只能在选择列表中指定一个表达式".错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在MS SQL 2012 Express上运行以下查询:
I'm trying to run the following query on 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"] + "')"
);
但是出现以下错误:
当未将
EXISTS
引入子查询时,在select
列表中只能指定一个表达式.
Only one expression can be specified in the
select
list when the subquery is not introduced withEXISTS
.
我该如何解决这个问题?
How can I solve this problem?
推荐答案
尝试一下:
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注入攻击带来的安全风险!
And I recommend you strongly to use parameters in your query to avoid security risks with sql injection attacks!
希望有帮助!
这篇关于如何修复“当子查询未与EXISTS一起引入时,只能在选择列表中指定一个表达式".错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文