一列一侧为空的连接问题 [英] Question on join where one column one side is null

查看:18
本文介绍了一列一侧为空的连接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表,存储候选人和他们的成绩.一个简单的 join 就可以通过匹配 ID 等来获取所有候选人及其成绩.

I have two tables, storing candidates and their grades. A simple join can get all the candidates and their grades, by matching IDs etc.

例如:

Alan    C
George  A

等等.但是:

Nina

妮娜的成绩为空,因为她没有参加考试.

The grade for Nina is null because she did not take the exam.

如何获得如下输出?

Alan   C
George A
Nina

所以仍然得到 Nina,即使她没有参加考试.我尝试过空检查,然后执行某些操作等.

So still get Nina, even though she did not take the exam. I've tried null checks and then performing something, etc.

谢谢

推荐答案

您想使用左联接.

select c.name, coalesce(g.grade,'')
    from candidate c
        left join grade g
            on c.candidate_id = g.candidate_id

这篇关于一列一侧为空的连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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