SQL - IN instead of UNION



如何使用IN而不是UNION从以下查询中获得相同的结果集?

select course_id 
from section 
where semester = 'Fall' 
and year = '2009' 
union
select course_id 
from section 
where semester = 'Spring' 
and year = '2010';

or开头:

select course_id
from section
where (semester = 'Fall' and year = '2009') or
(semester = 'Spring' and year = '2010');

如果course_id可以位于多行上,请使用select distinctunion会自动执行distinct

一些数据库支持元组格式,允许您执行以下操作:

select course_id
from section
where (semester, year) in ( ('Fall', '2009'), ('Spring', '2010'));

一些,但不是全部。 因此,这可能适用于也可能不适用于您正在使用的数据库。