avatar
s*r
1
I tried two following queries,
Select a.* from a
where a.id in (select id from b);
select a.* from a, b
where a.id=b.id
I assumed two queries shuold have same result. But actually the second query
have more results. Any idea?
Thanks,
avatar
I*e
2
You have NULL values in id column. The join syntax(2nd one) will remove all
NULL comparisons.

query

【在 s******r 的大作中提到】
: I tried two following queries,
: Select a.* from a
: where a.id in (select id from b);
: select a.* from a, b
: where a.id=b.id
: I assumed two queries shuold have same result. But actually the second query
: have more results. Any idea?
: Thanks,

avatar
s*r
3
I checked my tables. There should be no Null values. Actually 2nd talbe has
more records than 1st one.

all

【在 I******e 的大作中提到】
: You have NULL values in id column. The join syntax(2nd one) will remove all
: NULL comparisons.
:
: query

avatar
c*e
4
id不是唯一的

query

【在 s******r 的大作中提到】
: I tried two following queries,
: Select a.* from a
: where a.id in (select id from b);
: select a.* from a, b
: where a.id=b.id
: I assumed two queries shuold have same result. But actually the second query
: have more results. Any idea?
: Thanks,

avatar
I*e
5
You are selecting from two tables in the statement. Of course, it will have
more rows:
select a.* from a, b
where a.id=b.id
If you want do the same thing as the first one:
Select a.* from a
where exists (select id from b where a.id = b.id);
(this is based on the assumption that you do not have NULL values)
avatar
c*e
6
exists和in本来就没什么大区别

have

【在 I******e 的大作中提到】
: You are selecting from two tables in the statement. Of course, it will have
: more rows:
: select a.* from a, b
: where a.id=b.id
: If you want do the same thing as the first one:
: Select a.* from a
: where exists (select id from b where a.id = b.id);
: (this is based on the assumption that you do not have NULL values)

avatar
c*e
7
我觉得是这种情况
a.id b.id
111 111
222 111
.
.
.
这么一join,就会有两个a.*
如果你能把a.*里面所有的东西都group的话
应该是一样的结果

【在 c*******e 的大作中提到】
: id不是唯一的
:
: query

avatar
s*r
8
I think you are right. I will keep checking. I got table b from my co-worker
. I thought it should have distinct id. but actuall it is not.
I will remove duplicate id from b. Hopefully it will give me same result
this time.

【在 c*******e 的大作中提到】
: 我觉得是这种情况
: a.id b.id
: 111 111
: 222 111
: .
: .
: .
: 这么一join,就会有两个a.*
: 如果你能把a.*里面所有的东西都group的话
: 应该是一样的结果

avatar
c*e
9
join有时候是得小心,可能的话多搞几个field来join
有时候看着可能是redundant,但是那些table里面到底
数据质量怎么样,很难说,经常会有一些意向不到的问题

worker

【在 s******r 的大作中提到】
: I think you are right. I will keep checking. I got table b from my co-worker
: . I thought it should have distinct id. but actuall it is not.
: I will remove duplicate id from b. Hopefully it will give me same result
: this time.

avatar
s*r
10
Confirmed. You are right.
Must be very careful next time. The quality of data is a problem and it will
always be a problem. :(

【在 c*******e 的大作中提到】
: join有时候是得小心,可能的话多搞几个field来join
: 有时候看着可能是redundant,但是那些table里面到底
: 数据质量怎么样,很难说,经常会有一些意向不到的问题
:
: worker

avatar
c*e
11
我以前碰到过这样的问题,呵呵
我的意见是你如果不需要b里面的field
不要做join

will

【在 s******r 的大作中提到】
: Confirmed. You are right.
: Must be very careful next time. The quality of data is a problem and it will
: always be a problem. :(

avatar
I*e
12
This is my fault: IN and EXISTS are the same. NOT IN and NOT EXISTS are
different based on NULL.

【在 c*******e 的大作中提到】
: exists和in本来就没什么大区别
:
: have

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。