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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:24:04+00:00 2026-06-10T01:24:04+00:00

First, sorry if the title is confusing. SQL is not my strong suit and

  • 0

First, sorry if the title is confusing.
SQL is not my strong suit and I’ve been working on this for a while, my thoughts at the mmoment is something with a join, and group maybe.

Soto Example:

record | type | key1  | key2    | data1
---------------------------------------
1      | 1    | joe   | smoe    | 10
2      | 2    | homer | simpson | 20
3      | 1    | null  | null    | 30
4      | 3    | bart  | simpson | 40 

Where primary key is made up of id, key1, key2.

I only want rows of ‘type’ WHERE key1 is not null AND key2 is not null.

So since in record 3, type 1 has null keys, I therefore want all records of type 1 to not be included in the derived table.

  • 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-10T01:24:06+00:00Added an answer on June 10, 2026 at 1:24 am

    Here’s a correlated, “not exists” approach:

    select *
    from T as t1
    where not exists (
        select *
        from T as t2
        where t2.type = t1.type and (t2.key1 is null or t2.key2 is null)
    )
    

    And here’s one that uses a non-correlated query along with grouping. Perhaps it’s what you had in mind:

    select *
    from T as t1
    where t1.type in (
        select t2.type
        from T as t2
        group by t2.type
        having count(*) = count(t2.key1) and count(*) = count(t2.key2)
    )
    

    Since I understand mysql query plans can be sensitive to these things. Here’s the equivalent with a join:

    select t1.*
    from T as t1
        inner join
        (
            select t2.type
            from T as t2
            group by t2.type
            having count(*) = count(t2.key1) and count(*) = count(t2.key2)
        ) as goodtypes
            on goodtypes.type = t1.type
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry my title is not great, this is my first real punt at moving
First off, sorry if the title is confusing! I'm working on a part of
first of all sorry for the title. I know this is not so clear
Sorry, I wasn't sure exactly what title to give this and have not been
Let me first start off, sorry for the confusing title. I didn't know how
First of all, sorry about that title. I'm not the best at writing those
First of all sorry that I could not think of a more descriptive title.
First, sorry about the title of this question. I thought about it for a
First of all, sorry for this topic title, I couldn't manage to find another
first of all, sorry if the title is a bit confusing. i'm planning 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.