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

The Archive Base Latest Questions

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

I am not at all conversant in SQL so was hoping someone could help

  • 0

I am not at all conversant in SQL so was hoping someone could help me with a query that will find all the records in a parent table for which there are no records in a child table.

The following works for me to find parent records for specific child field values…

`SELECT    ParentTable.ParentID
 FROM      ParentTable INNER JOIN
             ParentTable ON ParentTable.ParentID = ChildTable.ChildID
 WHERE     (ChildTable.ChildField_ = '2131')
 Group By
   ParentTable.ParentID
 Having
   count(distinct ChildTable.ChildField) > 0`

Can I change the where clause some how to find parent’s with a count of zero child records.

Thanks.

  • 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:36:23+00:00Added an answer on May 24, 2026 at 12:36 am

    You can use a NOT EXISTS clause for this

    SELECT ParentTable.ParentID
    FROM ParentTable
    WHERE NOT EXISTS (
        SELECT 1 FROM ChildTable
        WHERE ChildTable.ParentID = ParentTable.ParentID
    )
    

    There’s also the old left join and check for null approach

    SELECT ParentTable.ParentID
    FROM ParentTable
    LEFT JOIN ChildTable
      ON ParentTable.ParentID = ChildTable.ParentID
    WHERE ChildTable.ChildID IS NULL
    

    Try both and see which one works better for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am guessing that not all SQL is created equally. I am diving into
I'm not all that familiar with jquery so I'm not quite sure how to
Most examples (if not all) that I see are the sort of a function
I have a query where not all conditions are necessary. Here's an example of
I have many constant arrays that do not all have the same number of
I have SQL rows with this information: Example - Exampleish (Exampleishbosh) not all have
I got a contenteditable iframe which can be shrinke so that not all of
Can NHibernate update some (not all) fields in the table row without retrieving any
I am still not all that good when it comes to writing Regex patterns
running this code I see that not all values of char (from 0 to

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.