如何使用Not IN与子查询中的子句 [英] How to use Not IN with where Clause in subqueries

查看:326
本文介绍了如何使用Not IN与子查询中的子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI Everyone



我需要有关Sql查询的帮助





从country ='india'的国家/地区选择*(他们bith是同一张桌子)

并且不存在

select * from country are country ='Nepal'





请一些人帮我获取不同的记录(第二次查询中没有,但存在于第一次查询中)。



当我执行它时,它返回给我没有值。

实际上我应该返回不在的值第二个查询。





谢谢

解决方案

试试这个



 如果 存在选择 * 来自国家其中国家/地区= '  india'
选择 * 来自国家/地区 where country = ' india'
else
选择 * 来自国家/地区= country = ' 尼泊尔'


为什么你不能简单地使用它:

 选择 * 来自国家其中 country = '  india'   AND  country<> ' 尼泊尔' 



OR

 选择 * 来自国家 where  country = '  india'  AND  country!= ' 尼泊尔' 


使用除外: http://technet.microsoft.com/en -us / library / ms188055.aspx [ ^ ]

HI Everyone

I need help with Sql query


select * from country where country = 'india' (they bith are same table)
and not exists
select * from country were country='Nepal'


Please can some one help me to get the distinct records(which are not there in 2nd query but exists in 1st query) .

When I am executing this its returning me no values.
Actually I should return the values which are not in the second query.


Thanks

解决方案

try this

if exists (select * from country  where country ='india')
select * from country  where country ='india'
else 
select * from country were country='Nepal'


why can't you simply use this:

select * from country where country = 'india' AND country <> 'Nepal'


OR

select * from country where country = 'india' AND country !='Nepal'


Use EXCEPT: http://technet.microsoft.com/en-us/library/ms188055.aspx[^]


这篇关于如何使用Not IN与子查询中的子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆