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 6180045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:46:38+00:00 2026-05-24T00:46:38+00:00

The table I’m using has 3 important columns on which to exclude entries in

  • 0

The table I’m using has 3 important columns on which to exclude entries in a table. I’ll call them:

SampleTable:

Thing_Type (varchar)
Thing_ID (int)
Parent_ID (int)

I want to find all ‘leaf’ entries of a specific type. However, it is possible that an entry of that type has a child that is not of that type, and thus I don’t want to exclude it without first filtering the table to only that type. Then I want to include all entries which have an ID that is not present anywhere in the ParentID column.

There’s no EXISTS in the tool I’m using (not that I’m sure it would help).

Ignoring the fact that the tool I’m using doesn’t like the following, and that it might not be syntactically correct, here’s what I feel it should be like.

SELECT * FROM (
    SELECT *
    FROM SampleTable
    WHERE SampleTable.Thing_Type = 'DesiredType'
)
WHERE Thing_ID NOT IN Parent_ID

I’m pretty sure this is wrong but I’m not sure how to make it right.

  • 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-05-24T00:46:39+00:00Added an answer on May 24, 2026 at 12:46 am

    First, NOT IN has to go against a set, not a single value, so NOT IN parent_id doesn’t actually make sense. This is one way to approach this problem:

    SELECT
        thing_type,
        thing_id,
        parent_id
    FROM
        Sample_Table T1
    WHERE
        thing_type = 'Desired Type' AND
        thing_id NOT IN (
                SELECT parent_id
                FROM Sample_Table T2
                WHERE T2.thing_type = 'Desired Type'
        )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Table A has column X, which is an int made up of the concatenation
Table view cell management has driving me crazy from past two days. Please check
Table IMAGES : columns- imageID, Image, and categoryID*(this being the foreign key) Table CATEGORIES
Table Definition Model Definition Code using MyRandomizer.Models; namespace MyRandomizer { class Program { static
Table 1: AccountId, ReferenceId, Name, (lots of other columns) Table 2: AccountId, ReferenceId, (other
Table: Customer with columns Start_Time and End_Time. I need to add a new column
Table items keeps track of the different types of items that can be stocked.
Table schema is set up something like this: userID Points timestamp 1 40 3
Table: <table id='t1' style='border:1px solid #000000'> <tr> <td><span id='flight_1'>1</span></td><td>1</td> </tr> <tr> <td><span id='flight_2'>2</span></td><td>2</td> </tr>
table structure: sysdurationtimeday , sysdurationtimehour, sysdurationtimeminute 1, 12,10 3, 23,10 0, 0,10 i have

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.