Simplifying SQL Query

Kuler Master 266 Reputation points
2023-04-27T00:00:48.5833333+00:00

Can be this query simplified?


    SELECT 
		* 
	FROM 
		Plan
	WHERE 
		IsPaid = 0	
	AND
		Id IN(SELECT PlanId FROM Reminders WHERE SubtypeId = 1)
	AND
		Id NOT IN(SELECT PlanId FROM Reminders WHERE SubtypeId = 2);

Azure SQL Database
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,670 questions
{count} votes

Accepted answer
  1. LiHongMSFT-4306 26,706 Reputation points
    2023-04-27T01:46:14.9966667+00:00

    Hi @Kuler Master

    How about this query:

    SELECT * 
    FROM Plan
    WHERE IsPaid = 0	
      AND Id IN(SELECT PlanId FROM Reminders WHERE SubtypeId = 1
                EXCEPT 
    			SELECT PlanId FROM Reminders WHERE SubtypeId = 2)
    

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.