I'm in desperate need of some help here.
我迫切需要一些帮助。
My problem is this: There are two tables in my database, tblSubmission
and tblStudent
. tblStudent
is linked with tblSubmission
by the student_id
key. Some of the rows in tblStudent
have been deleted, and are therefore unlinked to their row in tblSubmission
.
我的问题是:我的数据库中有两个表,tblSubmission和tblStudent。 tblStudent通过student_id键与tblSubmission链接。 tblStudent中的某些行已被删除,因此在tblSubmission中与其行无法链接。
What I need to do is compare the two tables, and find the student_id
's that exist in tblSubmission
, but NOT in tblStudent
, but the results from tblSubmission
have to have a column where app_id
equals 358.
我需要做的是比较两个表,找到tblSubmission中存在的student_id,但不是tblStudent,但是tblSubmission的结果必须有一个app_id等于358的列。
Checking through these rows manually is not an option since there are thousands of them. I've tried many queries already, using the most SQL I know and clauses like NOT EXISTS and NOT IN, but to no avail.
手动检查这些行不是一个选项,因为它们有数千个。我已经尝试了很多查询,使用我所知道的最多的SQL和条款,如NOT EXISTS和NOT IN,但无济于事。
1 个解决方案
#1
3
This will show all records in tblSubmission that have not a correlated record in tblStudent:
这将显示tblSubmission中tblStudent中没有相关记录的所有记录:
SELECT tblSubmission.*
FROM tblSubmission left join tblStudent on tblSubmission.student_id = tblStudent.student_id
WHERE tblStudent.student_id is null
AND app_id = 358
or also:
SELECT tblSubmission.*
FROM tblSubmission
WHERE student_id not in (select student_id from tblStudent)
AND app_id = 358
#1
3
This will show all records in tblSubmission that have not a correlated record in tblStudent:
这将显示tblSubmission中tblStudent中没有相关记录的所有记录:
SELECT tblSubmission.*
FROM tblSubmission left join tblStudent on tblSubmission.student_id = tblStudent.student_id
WHERE tblStudent.student_id is null
AND app_id = 358
or also:
SELECT tblSubmission.*
FROM tblSubmission
WHERE student_id not in (select student_id from tblStudent)
AND app_id = 358