SQL:即使没有匹配项,也返回一些值
我有一个sql查询,我在其中传递学生ID“in”子句。 如果没有与给定id匹配的记录,则不会返回任何内容。 我希望查询返回false或notexist等内容,即使没有记录匹配 //伪查询(为了简洁起见,我限制查询一个表,实际查询涉及其他表。)SQL:即使没有匹配项,也返回一些值,sql,Sql,我有一个sql查询,我在其中传递学生ID“in”子句。 如果没有与给定id匹配的记录,则不会返回任何内容。 我希望查询返回false或notexist等内容,即使没有记录匹配 //伪查询(为了简洁起见,我限制查询一个表,实际查询涉及其他表。) 应用或为空 Select s.student_id from STUDENTS s WHERE s.student_id in (?,?,?) or s.student_id is null; 如果要连接,请使用左连接: select s.st
应用
或为空
Select s.student_id
from STUDENTS s
WHERE s.student_id in (?,?,?)
or s.student_id is null;
如果要连接,请使用左连接:
select s.student_id
from students s
left join othertable o
on o.something = s.something
WHERE s.student_id in (?,?,?)
or s.student_id is null;
如果学生在右边:
select s.student_id
from othertable o
left join students s
on o.something = s.something
and s.student_id in (?,?,?) -- we put this into the join clause so we don't need the "or is null"
;
学生是否有表格多行或大数据?
select s.student_id
from othertable o
left join students s
on o.something = s.something
and s.student_id in (?,?,?) -- we put this into the join clause so we don't need the "or is null"
;
IF EXISTs(Select student_id from STUDENTS WHERE s.student_id in (?,?,?))
BEGIN
Select student_id from STUDENTS WHERE s.student_id in (?,?,?)
END
ELSE
select 0