由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - please help with this left join question
相关主题
请教一个query如何完成这个sql?
急问一个关于T-SQL的问题,谢谢[转载] 求教数据库的query optimization 工作的面试
SQL求助:两个表各自求Count有什么优化query的常用方法
[转载] Can anyone interpret this simple SQL?query 求助
请教怎么来log duration of a MYSQL procedure?怎么求和
问一个queryhow to write this query
1. Oracle vs. SQL92 Re: Justquery running long time
这个 query 为什么可以 update multiple rows请问个join的问题
相关话题的讨论汇总
话题: join话题: left话题: select话题: rows话题: question
进入Database版参与讨论
1 (共1页)
a********e
发帖数: 198
1
I run the simple query in MS sql2012
SELECT count(*) from PNTD.dbo.PEOPLE p
LEFT JOIN PNTD.dbo.AUTHORS at ON at.PEOPLEID = p.PEOPLEID ;
SELECT count(*) from PNTD.dbo.PEOPLE p
the return are 586 and 560.
why the left join return more rows? should the first query return less rows?
B*****g
发帖数: 34098
2
你比加一下 SELECT p.* 不就知道了?

rows?

【在 a********e 的大作中提到】
: I run the simple query in MS sql2012
: SELECT count(*) from PNTD.dbo.PEOPLE p
: LEFT JOIN PNTD.dbo.AUTHORS at ON at.PEOPLEID = p.PEOPLEID ;
: SELECT count(*) from PNTD.dbo.PEOPLE p
: the return are 586 and 560.
: why the left join return more rows? should the first query return less rows?

t****n
发帖数: 10724
3
because one person can write many books/articles. PeopleID in table Authors
is not the primary key. Most likely PeopleID + BookID is the primary key.
D*J
发帖数: 141
4
left join will add rows from the first table where there is no match in the
second table. there must be some rows (26 most likely) in PEOPLE which do
not have corresponding row in the AUTHORS table. which means 26 people are
not authors, most likely.

rows?

【在 a********e 的大作中提到】
: I run the simple query in MS sql2012
: SELECT count(*) from PNTD.dbo.PEOPLE p
: LEFT JOIN PNTD.dbo.AUTHORS at ON at.PEOPLEID = p.PEOPLEID ;
: SELECT count(*) from PNTD.dbo.PEOPLE p
: the return are 586 and 560.
: why the left join return more rows? should the first query return less rows?

c*****d
发帖数: 6045
5
你的回答解释不了他了问题
如果是你说的情况,people表这样
p1, p1_name
p2, p2_name
p3, p3_name
author表这样
a1, p1
a2, p2
SELECT * from PNTD.dbo.PEOPLE p
LEFT JOIN PNTD.dbo.AUTHORS at ON at.PEOPLEID = p.PEOPLEID ;
返回
p1, a1
p2, a2
p3, null
他的查询
SELECT count(*) from PNTD.dbo.PEOPLE p
LEFT JOIN PNTD.dbo.AUTHORS at ON at.PEOPLEID = p.PEOPLEID ;
应该返回3
SELECT count(*) from PNTD.dbo.PEOPLE p
应该返回3

the

【在 D*J 的大作中提到】
: left join will add rows from the first table where there is no match in the
: second table. there must be some rows (26 most likely) in PEOPLE which do
: not have corresponding row in the AUTHORS table. which means 26 people are
: not authors, most likely.
:
: rows?

j**********2
发帖数: 1495
6
因为AUTHORS table里有重复的PEOPLEID吧,这些重复的ID和people table有multiple
mach
s**********o
发帖数: 14359
7
1个人可以是多个AUTHOR啊,
p*, at.*
count的是JOIN出来的RECORD
1 (共1页)
进入Database版参与讨论
相关主题
请问个join的问题请教怎么来log duration of a MYSQL procedure?
求解释问一个query
问个SQL的问题1. Oracle vs. SQL92 Re: Just
我也问一个sql querry的问题这个 query 为什么可以 update multiple rows
请教一个query如何完成这个sql?
急问一个关于T-SQL的问题,谢谢[转载] 求教数据库的query optimization 工作的面试
SQL求助:两个表各自求Count有什么优化query的常用方法
[转载] Can anyone interpret this simple SQL?query 求助
相关话题的讨论汇总
话题: join话题: left话题: select话题: rows话题: question