空结果SQL查询。 [英] Empty result SQL query.

查看:102
本文介绍了空结果SQL查询。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试从表std_details中检索StudentID,FirstName,LastName和CGPA,这取决于学生采用set模块的条件。这是我设计的querry,不幸的是它返回并且空集:

Hi,
I'm trying to retreive the StudentID, FirstName, LastName and CGPA from the table std_details this based on the condition that the student takes a set module. Here is the querry that I designed unfortunately it return and empty set:

SELECT 
	std_details.StudentID, 
	std_details.FirstName, 
	std_details.LastName, 
	std_details.CGPA 
FROM std_details 
INNER JOIN csr_courses 
	ON std_details.StudentID = csr_courses.StudentID 
WHERE csr_courses.Course_1 = 'PHIL340' 
OR csr_courses.Course_2 = 'PHIL340' 
OR csr_courses.Course_3 = 'PHIL340' 
OR csr_courses.Course_4 = 'PHIL340' 
OR csr_courses.Course_5 = 'PHIL340'
;





我不确定我是否正在加入,我对sql很新。



这是csr表的一些示例数据:

http://hpics.li/bd9a863





和标准表格:

http ://hpics.li/13384e0



确切的错误代码是:



I'm not sure I'm doing the Join right, I'm quite new to sql.

Here is some sample data for the csr table:
http://hpics.li/bd9a863


and fort the std table:
http://hpics.li/13384e0

The exact error code is:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INNER JOIN csr_courses ON std_details.StudentID = csr_courses.StudentIDWHERE csr' at line 1

推荐答案

您需要使用别名+ RIGHT JOIN,这意味着:从 csr_courses 获取所有记录并匹配来自 std_details的数据

You need to use aliases + RIGHT JOIN, which means: get all records from csr_courses and matching data from std_details:
SELECT sd.StudentID, sd.FirstName, sd.LastName, sd.CGPA
FROM std_details sd RIGHT JOIN csr_courses cc ON sd.StudentID = cc.StudentID
WHERE cc.Course_1 = 'PHIL340' OR cc.Course_2 = 'PHIL340' OR cc.Course_3 = 'PHIL340' OR cc.Course_4 = 'PHIL340' OR cc.Course_5 = 'PHIL340'





详情请见:

SQL连接的可视化表示 [ ^ ]

MySQL JOIN [ ^ ]



顺便说一下:你确定 csr_courses 包含在中搜索数据Course_x 字段?



For further information, please see:
Visual Representation of SQL Joins[^]
MySQL JOIN[^]

By The Way: Are you sure that csr_courses contains searched data in Course_x field?


这篇关于空结果SQL查询。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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