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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:39:57+00:00 2026-05-28T01:39:57+00:00

Need to find records in subinv that do NOT have a listing in subinv

  • 0

Need to find records in subinv that do NOT have a listing in subinv table with substatus 1
when there is a listing in inv with status 1.

There is only one record per part number in inv, but can be several records in subinv with one of several status numbers. My statement returns no rows, shows no errors, but there are records that qualify.

SELECT m.partnum        
  FROM inv m, 
       subinv s     
 WHERE m.status = '1'
   AND not exists (SELECT s.partnum     
                     FROM subinv s1
                    WHERE s1.substatus = '1')       
  • 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-28T01:39:58+00:00Added an answer on May 28, 2026 at 1:39 am

    You have a Cartesian product in your outer query, which is not good (especially as you don’t want that join anyway), and you need to specify the part number in the EXISTS query:

    SELECT m.partnum
      FROM inv AS m
     WHERE m.status = '1'
       AND NOT EXISTS
           (SELECT *
              FROM SubInv AS s1
             WHERE s1.substatus = '1'
               AND s1.partnum = m.partnum
           );
    

    This features a correlated sub-query for the NOT EXISTS. It would be worth checking the performance of a filtered OUTER JOIN:

    SELECT i.partnum
      FROM inv AS i
      LEFT JOIN subinv AS s ON s.partnum = i.partnum AND s.substatus = '1'
     WHERE i.status = '1'
       AND s.substatus IS NULL;
    

    The LEFT JOIN condition will generate a NULL for s.substatus when there is no row with s.substatus = '1', and the WHERE clause only selects such rows. Not blindingly obvious as a transform, but it might be faster than the sub-query simply because it is a join rather than a sub-query that has to be executed for each row in the main inv table (that satisfies status = '1').

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

Sidebar

Related Questions

I need to find records in a dataset that have certain values from more
I need to find all the records that have no associated records in any
I need to find all patrons that have at least 1 circulation record. Here's
I have a legacy table that contains 'master' records and associated detail records. Detail
I need to find all records that were created on a specific day of
I'm trying to find all records in database that have exactly the same set
I need to find out the total number of records that were created on
I have one mysql table with the following set of records. Product_id reg_price sale_price
I have a database with a table that records data coming from various sources.
I have a field that is a decimal date (YYYYMMDD). I need to find

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.