从结果中排除mysql中的子查询结果中的某些内容


excluding from result something that is in a subquery result in mysql

是否可以不在子查询中的结果中显示某些内容。

示例:表1:有4个数字,1,2,3,4。因此,从表1中选择*显示4个结果

可以制造吗

    select * from table1 where not exists(select * from table1 where num = 3)

所以结果是1,2,4。基本上从结果中删除子查询结果中的某些内容。

我知道存在不起作用,因为它只给出真-假,但还有其他方法吗?

谢谢大家。

select * from table1 where num <> 3;

select * from table1 where id NOT IN (select id from table2 where num = 3);

详细说明你想要什么。

您可以使用NOT IN,但子查询必须只返回一列(我认为exists也是如此)。类似这样的东西:

SELECT * FROM table WHERE column1 NOT IN (SELECT column1 FROM table WHERE column2 = 3)