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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:33:58+00:00 2026-05-30T22:33:58+00:00

I had a hard time coming up with a title for this question, but

  • 0

I had a hard time coming up with a title for this question, but I think it may be easy for someone who is an SQL guru.

Tables:

SIMULATION: ID, SIMULATION_SET_ID, EXECUTION_STATUS
SIMULATION_SET: SET_ID 
SIMULATION_BATCH: ID
BATCH_ELEMENT: SIMULATION_BATCH_ID, SIMULATION_SET_ID

(In words, a set contains a bunch of simulations. A batch contains a bunch of sets via an intermediate table. The Batch is really a meta-container to group sets based on when they are requested, and are used as a container, but don’t themselves contain a status.)

I am trying to return a count of completed batches, and a completed batch would be one in which all of the simulations have an execution status of COMPLETED. However, I seem to be getting any batch that any completed simulation, even if they all aren’t. This was my attempt:

SELECT COUNT(DISTINCT B.ID) 
FROM SIMULATION_BATCH B 
INNER JOIN BATCH_ELEMENT BE ON BE.SIMULATION_BATCH_ID=B.ID 
INNER JOIN SIMULATION S ON S.SIMULATION_SET_ID=BE.SIMULATION_SET_ID 
WHERE S.EXECUTION_STATUS ='COMPLETED'";

So after looking back I see this doesn’t work. I tried to add in a AND NOT EXISTS(SELECT…) clause to try to rule out batches that had simulations where the execution status was not completed, but that didn’t work at all, it consistently returned an empty set when anything was running. This is what I added:

AND NOT EXISTS (SELECT SIM.ID 
FROM SIMULATION SIM 
INNER JOIN BATCH_ELEMENT BE2 ON BE2.SIMULATION_SET_ID=SIM.SIMULATION_SET_ID  
WHERE BE.SIMULATION_BATCH_ID=B.ID AND SIM.EXECUTION_STATUS != 'COMPLETED' );

Thanks for any insight into this. I think I need to better learn subqueries but I’m not sure. After I figure out how to get a count, I need to get a list of the batches with a bunch of info about them, but I think I can do that if I can get a count.

Update: I’ve been working on this all day, haven’t made that much progress except more wrong ones. I was thinking an easier way to describe what I’m looking for is I want Batches where ALL Simulations in the batch meet some criteria (like status is omplete). I can do this when ANY (at least 1) Simulation meets the criteria, but it’s the ALL that seems to be throwing me. Any ideas would be greatly appreciated.

  • 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-30T22:34:00+00:00Added an answer on May 30, 2026 at 10:34 pm

    I think I see a typo/bug in the subquery that explains why the overall query “consistently returned an empty set when anything was running.”

    See this line of your subquery:

    WHERE BE.SIMULATION_BATCH_ID=B.ID AND SIM.EXECUTION_STATUS != 'COMPLETED' );
    

    I think you meant to have this instead:

    WHERE BE2.SIMULATION_BATCH_ID=B.ID AND SIM.EXECUTION_STATUS != 'COMPLETED' );
    

    If that fixes the problem, then you could also try simplifying the query with something like this:

    SELECT COUNT(DISTINCT B.ID) 
    FROM SIMULATION_BATCH B 
    INNER JOIN BATCH_ELEMENT BE ON BE.SIMULATION_BATCH_ID=B.ID 
    AND NOT EXISTS (
        SELECT SIM.ID
        FROM SIMULATION SIM
        INNER JOIN BATCH_ELEMENT BE2 ON BE2.SIMULATION_SET_ID=SIM.SIMULATION_SET_ID  
        WHERE BE2.SIMULATION_BATCH_ID=B.ID AND 
        SIM.EXECUTION_STATUS != 'COMPLETED' );
    

    This assumes that:

    1. A batch always has at least one batch element.
    2. A batch element always has at least one simulation.

    It looks like the first case is true since you wrote, “The batch_element record is inserted when the batch is created.” But I’m not sure about the second one.

    Good luck!

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

Sidebar

Related Questions

I asked this question before, but had a hard time showing which edits I
I'm sure this is fairly easy, but I've kind of had a hard time
This might be a simple question, but I've had a hard time pinning down
Had a hard time coming up with a concise title for this. I'm sure
I had a hard time coming up with a title, so I hope this
Apologies for the less than ideal title; had a hard time coming up with
Ok, I had a hard time coming up with a title, as you can
Please forgive the awkward title. I had a hard time distilling my question into
I have this simple problem but I had a hard time of finding a
If this was previously talked about, I'm sorry, I had a hard time searching

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.