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

  • Home
  • SEARCH
  • 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 8869525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:29:55+00:00 2026-06-14T17:29:55+00:00

I am quite new to SQL and while I can get around writing most

  • 0

I am quite new to SQL and while I can get around writing most of the queries, I am not getting anywhere with this one. I want to achieve this in a single query that I can execute using JPA.

TABLE RULE:
RULE_ID   ENABLED
-----------------
1         0
2         0
3         0
4         1
5         1

TABLE MISC:
MISC_ID
--------
1
2

TABLE HOLD:
HOLD_ID   MISC_ID   RULE_ID   READY
------------------------------------
1         1         1         1       
2         1         2         1       
3         1         3         1       
4         2         4         0      
5         2         1         1       

I want to select from HOLD only the MISC_IDs where each row has READY=1 and RULE_ID is in (RULE_IDs where ENABLED=0). In the above example, the query should return MISC_ID = {1} since HOLD_IDs 1, 2 and 3 all have READY=1 and RULEs 1, 2 and 3 are all disabled.

MISC_ID 2 should not be returned since HOLD_ID 4 has READY=0.

The tables MISC and HOLD have millions of rows but RULE is fairly small (<1000 rows).

Any suggestions on how I could write a native SQL to achieve this? PL/SQL is not an option.

  • 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-14T17:29:56+00:00Added an answer on June 14, 2026 at 5:29 pm
    SELECT MISC_ID
    FROM HOLD
    
    GROUP BY MISC_ID
    HAVING MIN(READY) <> 0;
    

    Example run:

    $ with HOLD (HOLD_ID, MISC_ID, RULE_ID, READY)
    as (values
        (1,1,1,1),
        (2,1,2,1),
        (3,1,3,1),
        (4,2,4,0),
        (5,2,1,1)
    )
    
    select MISC_ID
    from HOLD
    
    group by MISC_ID
    having min(READY) <> 0;
    
     misc_id
    ---------
           1
    (1 row)
    

    Amended query to handle joining rules:

    SELECT HOLD.*, RULE.*
    
    FROM HOLD
    
    INNER JOIN RULE
    ON HOLD.RULE_ID = RULE.RULE_ID AND RULE.ENABLED = 0
    
    WHERE MISC_ID IN (
        SELECT MISC_ID
        FROM HOLD
    
        GROUP BY MISC_ID
        HAVING MIN(READY) <> 0
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm quite new to sql and I'm having trouble writing this i have a
I am quite new to writing SQL triggers and I had one working for
Original Question: I am new to SQL server and can't quite find what I
I'm quite new to PL/SQL, and am using Oracle SQL Developer to write a
Iam quite new to functions in SQL and I would like to create a
I am quite new with Linq to SQL and MVC but I follow the
How do I prevent SQL injection when it comes to ColdFusion? I'm quite new
I'm fairly new to SQL, but trying to write quite a complicated query, but
I have this: var blockRegEx = new Regex((proc sql;)(.*?)(quit;), RegexOptions.IgnoreCase | RegexOptions.Multiline); but it
This is my first question here on StackOverflow, and quite frankly I'm fairly new

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.