Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8506147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:30:56+00:00 2026-06-11T02:30:56+00:00

Here is my CTE/SQL statement: with cte as ( … ) select 1, 0,

  • 0

Here is my CTE/SQL statement:

with cte as (
    ...
)

select 1, 0, q.quadrantID, 0, '', 1
from Quadrants q
where q.quadrantID not in (select cte.quadrantID from cte)
order by quadrantID ASC

The Quadrants table has 6 records.

The CTE in this scenario doesn’t return any records. My select should return the 6 records from Quadrants, but it doesn’t. Why is that?

If I run the following statement:

select 1, 0, q.quadrantID, 0, '', 1
from Quadrants q
where q.quadrantID not in (5)
order by quadrantID ASC

It will return 5 of the 6 rows, like it’s supposed to.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:30:58+00:00Added an answer on June 11, 2026 at 2:30 am

    Are you aware that NOT IN will return incorrect results if your CTE is returning NULL in the data.

    Try running this query and see the results you will get zero records

    select 1, 0, q.quadrantID, 0, '', 1 
    from Quadrants q 
    where q.quadrantID not in (NULL,5) 
    order by quadrantID ASC
    

    You should write your query with NOT EXISTS read this for further info.

    http://decipherinfosys.wordpress.com/2007/01/21/32/

    Edit: I wrote your query with NOT EXISTS clause ,Try this

    select 1, 0, q.quadrantID, 0, '', 1 
    from Quadrants q 
    where NOT EXISTS
    (
    SELECT 1  from cte WHERE cte.quadrantID=q.quadrantID 
    )
    order by quadrantID ASC 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my SQL script CREATE TABLE tracks( track_id int NOT NULL AUTO_INCREMENT, account_id
I've cretaed a TVF which returns a table with parent-records from a recursive CTE
Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`
;with cte as ( select FingerId, [Date], LogTime, row_number() over(partition by FingerId order by
Using SQL Server 2008. Here is a simplified example of my problem: WITH cte
first i must admit that i'm not very familiar with sql server's recursive CTE's
I need to update some records here are the table structures Table A is
Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
I have written a table-valued UDF that starts by a CTE to return a
I just read this link http://msdn.microsoft.com/en-us/library/ms186243.aspx Here is the code to create table and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.