作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
两个mysql表,如A和B
emp_A(id,name,some_text) PK is: id
emp_B(sr_no,emp_id,loc,adrr) PK is: emp_id+sr_no
emp_sr(sr_no,a,b) PK is: sr_no
我的 table 是这样的。我要查询如下
select A.name, B.loc
from emp_A, emp_B B
where A.id=B.em_id
and sr_no =123
emp_A表有大约3L条记录emp_B表有大约8L条记录。
如何加快我的连接查询?
请帮帮我??????
最佳答案
使用连接的 ON
子句,而不是 WHERE
。
select A.name, B.loc from emp_A
inner join emp_B B on A.id=B.em_id and sr_no =123
当您仅使用 WHERE
子句时,首先将 A 中的每条记录连接到 B 中的每条记录,然后过滤掉一些记录。因此,您正在构建一个巨大的表作为中间步骤。
当您使用 ON
子句时,在连接发生时,不匹配的记录将被过滤掉。
关于mysql - 如何在mysql中紧固连接查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13877387/
我是一名优秀的程序员,十分优秀!