本文介绍了空结果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表的一些示例数据:







和标准表格:





确切的错误代码是:



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

推荐答案

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'





详情请见:

[]

[]



顺便说一下:你确定 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查询。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 20:20