由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 这个问题的sql query为什么这样写?
相关主题
[转载] strong SQL skills?SQL Developer, how to switch schema?
请问个join的问题sqlsrv_query
Use a query to list the table names in the HR database schema??What does sum(2) mean?
求解释请问mysql查询时间太长怎么自动终止
请帮我看看,什么地方错了?question on JOIN on Oracle
[转载] Can anyone interpret this simple SQL?新手请教:为什么这个Query不work
sql面试题目求指点一个schema求教
请问这两个SQL QUERY有什么错?谁给我优化一下把重复的产品下架的SQL
相关话题的讨论汇总
话题: employee话题: company话题: name话题: join话题: works
进入Database版参与讨论
1 (共1页)
m******u
发帖数: 12400
1
schema has 4 tables:
employee(employee-name, street, city)
works(employee-name, company-name, salary)
company(company-name, city)
manages(employee-name, manager-name)
Question:
Find the names of all employees in the database who live in the same cities
as the companies for which they work.
Answer:
select e.employee-name
from employee e, works w, company c
where e.employee-name = w.employee-name and e.city = c.city
and w.company-name = c.company-name
I thought we just need to join employee table and company table on their
city column.
My question is what wrong with my thought?
Thanks for your time and participation.
c*****d
发帖数: 6045
2
如果只是employee和company连接
你的查询会返回所有相同city的employee和company
哪怕employee不为该company工作
x****e
发帖数: 1773
3
赞。
建议楼主建几个表,每个输入个几行数据,跑跑看看。个人觉得,这种方法对加深对常
用操作的理解非常有效。

【在 c*****d 的大作中提到】
: 如果只是employee和company连接
: 你的查询会返回所有相同city的employee和company
: 哪怕employee不为该company工作

m******u
发帖数: 12400
4
Thanks.
m******u
发帖数: 12400
5
schema has 4 tables:
employee(employee-name, street, city)
works(employee-name, company-name, salary)
company(company-name, city)
manages(employee-name, manager-name)
Question:
Find the names of all employees in the database who live in the same cities
as the companies for which they work.
Answer:
select e.employee-name
from employee e, works w, company c
where e.employee-name = w.employee-name and e.city = c.city
and w.company-name = c.company-name
I thought we just need to join employee table and company table on their
city column.
My question is what wrong with my thought?
Thanks for your time and participation.
c*****d
发帖数: 6045
6
如果只是employee和company连接
你的查询会返回所有相同city的employee和company
哪怕employee不为该company工作
x****e
发帖数: 1773
7
赞。
建议楼主建几个表,每个输入个几行数据,跑跑看看。个人觉得,这种方法对加深对常
用操作的理解非常有效。

【在 c*****d 的大作中提到】
: 如果只是employee和company连接
: 你的查询会返回所有相同city的employee和company
: 哪怕employee不为该company工作

m******u
发帖数: 12400
8
Thanks.
s********t
发帖数: 8
9
select e.employee-name
from employee e inner join works w on e.employee-name = w.employee-name
inner join company c on w.company-name = c.company-name
where e.city = c.city

这样写可以吗?两者区别是什么呢?
s********t
发帖数: 8
10
select e.employee-name
from employee e inner join works w on e.employee-name = w.employee-name
inner join company c on w.company-name = c.company-name
where e.city = c.city

这样写可以吗?两者区别是什么呢?
s********t
发帖数: 8
11
select e.employee-name
from employee e inner join works w on e.employee-name = w.employee-name
inner join company c on w.company-name = c.company-name
where e.city = c.city

这样写可以吗?两者区别是什么呢?
w****o
发帖数: 36
12
Inner Join vs Join:
They are functionally equivalent
http://stackoverflow.com/questions/565620/difference-between-jo
q*********8
发帖数: 188
13
以上的几个query结果应该相同。 Performance可以会有不同, 建议使用SQL Server自
带的Execution plan来看看如果优化。
1 (共1页)
进入Database版参与讨论
相关主题
谁给我优化一下把重复的产品下架的SQL请帮我看看,什么地方错了?
问一个query,about Recursive Queries Using Common Table Expressions[转载] Can anyone interpret this simple SQL?
correlated subquerysql面试题目求指点
一个有关查询的语句请问这两个SQL QUERY有什么错?
[转载] strong SQL skills?SQL Developer, how to switch schema?
请问个join的问题sqlsrv_query
Use a query to list the table names in the HR database schema??What does sum(2) mean?
求解释请问mysql查询时间太长怎么自动终止
相关话题的讨论汇总
话题: employee话题: company话题: name话题: join话题: works