什么是数据库中的半连接? [英] What is semi-join in database?

查看:21
本文介绍了什么是数据库中的半连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试理解半连接的概念以及它与传统连接的不同之处时遇到了问题.我已经尝试了一些文章但对解释不满意,有人可以帮助我理解吗?

I am having trouble while trying to understand the concept of semi-join and how it is different from conventional join. I have tried some article already but not satisfied with the explanation, could someone please help me to understand it?

推荐答案

简单示例.让我们使用左外连接选择有成绩的学生:

Simple example. Let's select students with grades using left outer join:

SELECT DISTINCT s.id
FROM  students s
      LEFT JOIN grades g ON g.student_id = s.id
WHERE g.student_id IS NOT NULL

现在与左半连接相同:

SELECT s.id
FROM  students s
WHERE EXISTS (SELECT 1 FROM grades g
              WHERE g.student_id = s.id)

后者效率更高.

这篇关于什么是数据库中的半连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆