查询返回错误的结果,预计会有一行但是获得ALL

时间:2018-01-12 15:38:11

标签: mysql sql

下面我的陈述是返回表格的所有结果,而不仅仅是匹配的n1。我附上了结果的截图。我期待的只是第一行。有人可以帮我理解这里发生的事情吗? Result of the Query attached

Create View Proj_Display AS
select * from Proj_d
Where "n" in (Select Student from proj_d);

1 个答案:

答案 0 :(得分:2)

Create View Proj_Display AS
select * from Proj_d
Where "n1" in (Select Student from proj_d);

此查询现在检查表proj_d中是否存在值“n1”。这总是如此。 所以我想你想要这样的东西:

Create View Proj_Display AS
select * from Proj_d
Where Student  in (Select Student from proj_d WHERE Student = 'n1');

但是你可以在不使用子查询的情况下立即执行此操作:

Create View Proj_Display AS
select * from Proj_d
Where Student  = 'n1'

但是你可能需要提供更多你想要的信息