具有“不存在"的SQL查询;不工作 [英] SQL query with "not exists" not working
本文介绍了具有“不存在"的SQL查询;不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用一个简单的查询,但是我什么也没找到.目的是学习"不存在"的工作方式.我有一个简单的表,其中以"idUsuario"作为用户的默认ID和名称.
I'm trying to use a simple query but I'm not getting anywhere. The objective is to "learn" how "not exists" works. I have a simple table with "idUsuario" as default ID for users and a name.
SELECT * FROM usuario
WHERE NOT EXISTS (
SELECT * FROM usuario
WHERE u.idUsuario =16
)
在这里,我正在尝试从ID不为16的表中获取所有用户.但是,它只是获取了所有用户.我在做什么错了?
Here i'm trying to get ALL the users from the table where the ID IS NOT 16. But it just get all of them.. What am I doing wrong?
提前谢谢!
推荐答案
您应该将查询的结果与子查询的结果结合起来
You should join result from your query with result from the subquery as below
SELECT * FROM usuario u
WHERE NOT EXISTS (
SELECT * FROM usuario u1
WHERE u1.idUsuario = u.idUsuario
and u1.idUsuario =16
)
这篇关于具有“不存在"的SQL查询;不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文