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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:12:20+00:00 2026-06-10T03:12:20+00:00

I have tables set up like so: Parent —— id, … Child —– id,

  • 0

I have tables set up like so:

Parent
------
id, ...

Child
-----
id, parent_id, x, y

I want to find the Parents, or the distinct parent_id(s), if all of the rows in Child containing a given parent_id meet a criteria involving x and y(in my case x = y).

For example:

Parent
------
id
 1
 2
 3

Child
id, parent_id, x, y
1,      1,     2, 3
2,      1,     3, 4
3,      2,     5, 5
4,      2,     6, 7
5,      3,     8, 8
6,      3,     9, 9

would result in 3. Currently, I have a query that finds parent_ids that any of the children meet the criteria. I then use that to retrieve those records and check them in code if all the children meet the criteria. With the example data, I get parent_id 2 and 3, get the two parent records with all children, and evaluate. I want to do this with a single query, if possible.

  • 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-10T03:12:22+00:00Added an answer on June 10, 2026 at 3:12 am

    You can use NOT EXISTS

    SELECT id 
    FROM Parent p
    WHERE NOT EXISTS
    (
       SELECT 1 FROM Child c
       WHERE c.parent_Id = p.id
       AND c.x <> c.y
    )
    

    Edit: Here’s the sql-fiddle: http://sqlfiddle.com/#!3/20128/1/0

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

Sidebar

Related Questions

I have two tables like Parent-Child. In Parent table, there are 7211 records. In
I have two tables with a parent/child relationship. I want to update the parent
I have 2 tables set up like this (irrelevant rows omitted): > product -
Hello I have like this 2 tables class User public int UserId{get;set;} { ....
I have a set of tables that look like: workflows = Table('workflows', Base.metadata, Column('id',
Lets say I have two tables - child and parent with many-to-one relation. What
I have a typed dataset with two tables like this: Table A (Parent Table)
I have a set of tables with children of children, like so: Clients (PK
I have a bill of materials table that is set up like this: item
I quite often have rows of code like the following: UPDATE my_table SET name

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.