我有一个非常简单且不言自明的 SQL 语句:
ALTER PROCEDURE [dbo].[sp_getAllDebatesForAlias](@SubjectAlias nchar(30))
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT *
FROM tblDebates
WHERE (SubjectID1 in (SELECT SubjectID FROM tblSubjectAlias WHERE SubjectAlias = @SubjectAlias))
OR (SubjectID2 in (SELECT SubjectID FROM tblSubjectAlias WHERE SubjectAlias = @SubjectAlias)) ;
END
我确信有一种方法可以使该语句更有效,至少可以摆脱在该in
部分中多次创建同一个表,即
SELECT SubjectID FROM tblSubjectAlias WHERE SubjectAlias = @SubjectAlias
部分。
有任何想法吗?