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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:36:17+00:00 2026-05-15T14:36:17+00:00

Hopefully the title is clear enough! I’m looking for a single query that replicates

  • 0

Hopefully the title is clear enough! I’m looking for a single query that replicates the functionality of the following one, but without using a subquery:

select p_id from a_p 
 where a_id=1 
   and p_id not in (select p_id from a_p where a_id=2)

For example, table a_p has the following rows:

a_id | p_id
1    | 1
1    | 2
2    | 2

Here, p_id 1 is present for a_id 1 but not a_id 2 – the query above will return only p_id 1. Any ideas?

  • 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-15T14:36:18+00:00Added an answer on May 15, 2026 at 2:36 pm

    Without being able to use a subquery, that leaves you with using LEFT OUTER JOIN/IS NULL:

       SELECT a.p_id
         FROM A_P a
    LEFT JOIN A_P b ON b.p_id = a.p_id
                   AND b.a_id = 2
        WHERE a.a_id = 1
          AND b.p_id IS NULL
    

    Be aware that subquery performance is not the same across all database vendors. In PostgreSQL and Oracle, NOT IN, NOT EXISTS and LEFT JOIN/IS NULL are all equivalent. Only in MySQL is the LEFT JOIN/IS NULL more efficient.

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

Sidebar

Related Questions

Hopefully that title is clear enough. Anyways, it seems: [NSKeyedArchiver archiveRootObject:rootObject toFile:path]; is restricted
Hopefully this will be clear enough. I have a 2d map made of tiles,
Sorry for the rubbish title but hopefully this will explain: Given the table name
Hopefully the title is self explanatory, what is the advantage of using the .call()
Hopefully my title isn't too confusing. Anyways, I'm still learning CSS and right now
This is one of the hardest questions I've ever had to title here on
Hopefully more of a What am I doing wrong? than How do I? but
Hopefully this isn't too stupid but I want to make sure I'm doing this
another brain teaser. This isn't the usual but Apostrophes are breaking my Queries as
So the quick background is that I have a page listing a set of

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.