Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何限制左联接?_Mysql_Sql - Fatal编程技术网

Mysql 如何限制左联接?

Mysql 如何限制左联接?,mysql,sql,Mysql,Sql,我做了两张这样的桌子 degree_plan student_record ------------------------------ ---------------------------- major course course_no ID course_no grade ------------------------------ --------

我做了两张这样的桌子

degree_plan                              student_record
------------------------------      ----------------------------
major    course     course_no        ID       course_no     grade        
------------------------------      ----------------------------
COE      COE200        1             4455        1           A
COE      COE305        2             4455        2           C
COE      COE400        3             3333        4           B
SWE      SWE214        4
SWE      SWE344        5
SWE      SWE444        6
course\u no
是表之间的关系

我如何用SQL编写查询,得到这样的结果
,其中ID=4459,major=COE

--------------------------
major   course       grade
--------------------------
COE     COE200        A
COE     COE305        C
COE     COE400        NULL
您需要在where to filter(过滤的位置)中选择专业,请尝试以下方法:

select a.major, a.course, b.grade
from degree_plan a
left join studen`t_record b on b.course_no = a.course_no
where a.major = 'COE'
您甚至不需要like子句,因为主字段不长于COE

select a.mjor, a.course, b.grade 
from degree_plan as a
left join student_record as b on a.course_no=b.course_no and b.id=4455
where a.major='COE'

提示:
其中
<代码>左联接。只需在课程号上进行内部联接或左联接。检查有关此联接的一些文档。我尝试了左联接,但检索了所有左表。我需要检索左表,其中主要=COE@Steven您尝试的sql是什么?你甚至都不给我们。人们如何帮助您?虽然此代码可能会回答此问题,但提供有关为什么和/或如何回答此问题的其他上下文将显著提高其长期价值。请在您的答案中添加一些解释。@TobySpeight目前有一个公认的答案,尽管此代码可能会回答此问题,但提供有关为什么和/或如何回答此问题的附加上下文将显著提高其长期价值。请您在回答中添加一些解释。@TobySpeight我是开发者。我无法详细解释。我刚刚给出了解决方案。
select a.mjor, a.course, b.grade 
from degree_plan as a
left join student_record as b on a.course_no=b.course_no and b.id=4455
where a.major='COE'
   SELECT degree_plan.major, degree_plan.course, studen't_record.grade 
     FROM degree_plan
LEFT JOIN Student_record ON degree_plan.course_no=student_record.course_no where degree.major='COE';