avatar
aks a simple SQL question# Database - 数据库
l*n
1
【 以下文字转载自 shopping 讨论区 】
发信人: longtian (自由+回到地球), 信区: shopping
标 题: aks a simple SQL question
发信站: BBS 未名空间站 (Fri Dec 15 18:22:51 2006), 转信
two data set both have UserID, want to find out the UserID in the first
set but not in the second one.
You can not use select minus or any form of subqueries.
avatar
w*e
2
may I use cursor?

【在 l******n 的大作中提到】
: 【 以下文字转载自 shopping 讨论区 】
: 发信人: longtian (自由+回到地球), 信区: shopping
: 标 题: aks a simple SQL question
: 发信站: BBS 未名空间站 (Fri Dec 15 18:22:51 2006), 转信
: two data set both have UserID, want to find out the UserID in the first
: set but not in the second one.
: You can not use select minus or any form of subqueries.

avatar
t*g
3
select t1.userid
from t1 left outer join t2 on t1.userid = t2.userid
where t2.userid is null

【在 l******n 的大作中提到】
: 【 以下文字转载自 shopping 讨论区 】
: 发信人: longtian (自由+回到地球), 信区: shopping
: 标 题: aks a simple SQL question
: 发信站: BBS 未名空间站 (Fri Dec 15 18:22:51 2006), 转信
: two data set both have UserID, want to find out the UserID in the first
: set but not in the second one.
: You can not use select minus or any form of subqueries.

avatar
w*e
4
你这不对

【在 t*****g 的大作中提到】
: select t1.userid
: from t1 left outer join t2 on t1.userid = t2.userid
: where t2.userid is null

avatar
t*g
5
where?

【在 w*******e 的大作中提到】
: 你这不对
avatar
c*d
6
nod
should be:
select userid_1
from
(select t1.userid as userid_1, t2.userid as userid_2 from t1 left join t2 on
t1.userid=t2.userid)
where userid_2 is null

你这不对

【在 w*******e 的大作中提到】
: 你这不对
avatar
l*n
7
do not use subqueries

on

【在 c*****d 的大作中提到】
: nod
: should be:
: select userid_1
: from
: (select t1.userid as userid_1, t2.userid as userid_2 from t1 left join t2 on
: t1.userid=t2.userid)
: where userid_2 is null
:
: 你这不对

avatar
c*d
8
I do not know your exact requirements
but I guess you are required not to use subquery for performance reason
e.g.
select userid from t1 where userid not in (select userid from t2)
the above statement is resource-costing
But my answer is much efficient even if it is kind of subquery

do not use subqueries
on

【在 l******n 的大作中提到】
: do not use subqueries
:
: on

avatar
l*n
9
this is an interview question.
select the user names which are in table 1 but not in table 2. Do not us
e minus or any subquery
I think you answer still has subquery.

【在 c*****d 的大作中提到】
: I do not know your exact requirements
: but I guess you are required not to use subquery for performance reason
: e.g.
: select userid from t1 where userid not in (select userid from t2)
: the above statement is resource-costing
: But my answer is much efficient even if it is kind of subquery
:
: do not use subqueries
: on

avatar
t*g
10
try it before you conclude. the where clause is applied after left join
happens. no subquery is needed at all.

on

【在 c*****d 的大作中提到】
: nod
: should be:
: select userid_1
: from
: (select t1.userid as userid_1, t2.userid as userid_2 from t1 left join t2 on
: t1.userid=t2.userid)
: where userid_2 is null
:
: 你这不对

avatar
l*n
11
I think what you mean is right, but the answer you give includes subquer
y(from (select ***))
My answer is:
select table1.Name, table2.** from table1, table 2 where table1.UserId =
table2.UserId

【在 t*****g 的大作中提到】
: try it before you conclude. the where clause is applied after left join
: happens. no subquery is needed at all.
:
: on

avatar
t*g
12
my query was
select t1.userid
from t1 left outer join t2 on t1.userid = t2.userid
where t2.userid is null

【在 l******n 的大作中提到】
: I think what you mean is right, but the answer you give includes subquer
: y(from (select ***))
: My answer is:
: select table1.Name, table2.** from table1, table 2 where table1.UserId =
: table2.UserId

avatar
c*d
13
oops, you are right
I try the code and no subquery is needed

【在 t*****g 的大作中提到】
: try it before you conclude. the where clause is applied after left join
: happens. no subquery is needed at all.
:
: on

avatar
l*n
14
good,thank you very much

【在 t*****g 的大作中提到】
: my query was
: select t1.userid
: from t1 left outer join t2 on t1.userid = t2.userid
: where t2.userid is null

avatar
w*n
15
good!!

【在 t*****g 的大作中提到】
: my query was
: select t1.userid
: from t1 left outer join t2 on t1.userid = t2.userid
: where t2.userid is null

avatar
b*l
16
no need left outer join, just left join. will do the same.
avatar
t*g
17
what is left join? :)

【在 b****l 的大作中提到】
: no need left outer join, just left join. will do the same.
avatar
x*e
18
is this a DB board?
It seems you are the only one who talk in SQL.

【在 t*****g 的大作中提到】
: what is left join? :)
avatar
t*g
19
高手都不来,就我们半坛醋们在这里晃悠.

【在 x***e 的大作中提到】
: is this a DB board?
: It seems you are the only one who talk in SQL.

avatar
x*e
20
hehe,
至少你的概念比较清楚。

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