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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:30:48+00:00 2026-05-11T15:30:48+00:00

I have these two tables: CREATE TABLE x ( id INT NOT NULL, exclude

  • 0

I have these two tables:

CREATE TABLE x (     id INT NOT NULL,     exclude BIT NOT NULL,     PRIMARY KEY (id) );  CREATE TABLE y (     id INT NOT NULL,     field1 INT NOT NULL,     field2 INT NOT NULL,     field3 INT NOT NULL,     field4 INT NOT NULL,     field5 INT NOT NULL,     PRIMARY KEY (id) ); 

And this sproc:

CREATE PROCEDURE proc1 (     i1 INT,     i2 INT,     i3 INT,     i4 INT,     i5 INT ) BEGIN  SELECT     id FROM     y WHERE     field1 = i1,     field2 = i2,     field3 = i3,     field4 = i4,     field5 = i5     AND id NOT IN (         SELECT             y.id         FROM             y, x         WHERE             y.field1 = i1             AND y.field2 = i2,             AND y.field3 = i3,             AND y.field4 = i4,             AND y.field5 = i5             AND x.id = y.id             AND x.exclude = 1);  END IF; 

I basically want to get the id field from y except those that exist in x with exclude = 1, can this be done with joins or written in a better way?

Many thanks

Note: The reason a join is used in the ‘NOT IN’ subquery is for performance sake, table x contains a lot of records while the select statement on table y returns only a couple of records

Edit: Also please note that the id in y might or might not exist in x (otherwise a simple join will do), I want all the ids in y except those that exist in x with exclude = 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. 2026-05-11T15:30:48+00:00Added an answer on May 11, 2026 at 3:30 pm

    I’m not sure I follow your logic for using a join inside your subquery. You’re doing the same work twice.

    You could try:

    SELECT id FROM y WHERE field1 = 2 AND field2 = 3 AND field3 = 4 AND field4 = 5 AND field5 = 6 AND NOT EXISTS( SELECT x.id FROM x WHERE x.id = y.id AND x.exclude = 1 ) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 150k
  • Answers 151k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Depends on how you want to edit it. If you… May 12, 2026 at 9:51 am
  • Editorial Team
    Editorial Team added an answer For Emacs.app you can adopt a cleaner approach, and it… May 12, 2026 at 9:51 am
  • Editorial Team
    Editorial Team added an answer I dont think you need to fake flash at all,… May 12, 2026 at 9:51 am

Related Questions

(NOTE: This question is not about escaping queries, it's about escaping results) I'm using
I have two tables in my database, called ratings and movies . Ratings: |
I basically created some tables to play around with: I have Two main tables,
I'm currently using NHibernate as my data access layer, using Fluent NHibernate to create

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.