So imagine that I have this table (qwerty)
所以想象我有这张桌子(qwerty)
SectionID|UserID|Number
------------------------
10 150 1
10 140 0
10 130 0
20 150 1
20 160 1
20 165 0
20 130 0
25 150 0
25 170 1
The query I want to run is to select all the usersID
when the UserID (150)
has the number(1)
我要运行的查询是当UserID(150)具有数字(1)时选择所有usersID
Query with error:
查询错误:
SELECT UserID
FROM qwerty
WHERE SectionID = (SELECT SectionId FROM qwerty WHERE Userid = 150 and Number = 1)
Output:
150,140,130,160,165,130
1 个解决方案
#1
0
There is no reason for you to use this sub query. Use only the WHERE in the main query, like this:
您没有理由使用此子查询。仅使用主查询中的WHERE,如下所示:
SELECT UserID
FROM qwerty
WHERE Userid = 150 and Number = 1
#1
0
There is no reason for you to use this sub query. Use only the WHERE in the main query, like this:
您没有理由使用此子查询。仅使用主查询中的WHERE,如下所示:
SELECT UserID
FROM qwerty
WHERE Userid = 150 and Number = 1