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

The Archive Base Latest Questions

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

sorry for the confusing title. I have two tables, individu and orgcont . individu

  • 0

sorry for the confusing title.

I have two tables, individu and orgcont. individu looks something like:

individu
-------------
ind_id
org_id
email

orgcont looks something like:

orgcont
-------------
ind_id
function_code

I have many users that can belong to the same org_id and they each of their own ind_id. The ‘leaders’ of the org_id have a function code of ‘PRIM’, everyone else’s are irrelevant. I am trying to return a list of org_id and email of all of the users who have a ‘PRIM’ function code who have users that have NULL email addresses that are not ‘PRIM’.

I have something like this, but the results are not correct. Any help would be appreciated:

select
    i.email,
    i.org_id
from
    individu i,
    orgcont o,
    individu i2,
    orgcont o2
where
    i.ind_id = o.ind_id
    and i.org_id = i2.org_id
    and i2.ind_id = o2.ind_id
    and o.function_code = 'PRIM'
    and o2.function_code != 'PRIM'
    and i2.email is NULL
  • 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:03:18+00:00Added an answer on May 28, 2026 at 1:03 am

    Try it with exists:

    select
        i.email,
        i.org_id
    from
        individu i
        inner join orgcont o on
            i.ind_id = o.ind_id
    where
        o.function_code = 'PRIM'
        and exists (
            select
                1
            from
                individu i2
                inner join orgcont o2 on
                    i2.ind_id = o2.ind_id
            where
                i2.org_id = i.org_id
                and o2.function_code != 'PRIM'
                and i2.email is null
        )
    

    This will only return you one row for each leader with folks in their org with null email addresses, as opposed to your original query, which will return duplicate rows.

    Also note the join syntax–you want to do an inner join here, not a cross join, so do so explicitly.

    Additionally, you could have just done a select distinct, but that’s a little more expensive than the exists.

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

Sidebar

Related Questions

Sorry if my title is confusing. I have an assignment due that has to
Hello everybody and sorry for the rather confusing question-title. I have a Hibernate Class
Sorry if the title is confusing. I have several string expressions in an array
Sorry for the title may seem confusing. i have 2 element. with no relation
Sorry if the title is confusing. Here is the query I have Select MONTH(DATE(TIMESTAMP)),
I'm sorry for the little confusing title but say I have a class with
Sorry about that confusing title :) I have a resource, ComatosePage (used in the
sorry for the confusing title, its really hard for me to explain what i
Sorry for the confusing title, but it basically says it all. Here's the structures
Sorry if the title sounds confusing - but this is what I am trying

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.