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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:16:00+00:00 2026-06-15T15:16:00+00:00

I have the following (abridged schema) – 3 tables – user, job, job_type TABLE:

  • 0

I have the following (abridged schema) – 3 tables – user, job, job_type

TABLE: job_type
COLUMN: job_type_id
1           
2

TABLE: user
COLUMN: user_id
101
102
103

TABLE: job
COLUMNS: job_id | user_id | job_type_id
              4 |     101 |           1
              5 |     101 |           2
              6 |     102 |           1
              7 |     103 |           2

I want to write a query that returns all of the users who have a job in the job table where job_type_id = 1, but if they ALSO have a job with job_type_id = 2, to exclude them from the results. Therefore, the target resultset should return back user 102 only.

  • 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-15T15:16:01+00:00Added an answer on June 15, 2026 at 3:16 pm

    You haven’t indicate what DBMS you’re using, but here are some queries that should work in almost any:

    SELECT DISTINCT user_id
      FROM job j1
     WHERE job_type_id = 1
       AND NOT EXISTS
            ( SELECT 1
                FROM job j2
               WHERE job_type_id = 2
                 AND j2.user_id = j1.user_id
            )
    ;
    
    SELECT DISTINCT user_id
      FROM job
     WHERE job_type_id = 1
       AND user_id NOT IN
            ( SELECT DISTINCT user_id
                FROM job
               WHERE job_type_id = 2
            )
    ;
    
    SELECT DISTINCT j1.user_id
      FROM job j1
      LEFT
     OUTER
      JOIN job j2
        ON j1.user_id = j2.user_id
       AND j1.job_type_id = 1
       AND j2.job_type_id = 2
     WHERE j2.user_id IS NULL
    ;
    

    Some DBMSes also offer a special MINUS or EXCEPT feature that you can use. That would look something like this:

    SELECT user_id
      FROM job
     WHERE job_type_id = 1
    MINUS                          -- or EXCEPT
    SELECT user_id
      FROM job
     WHERE job_type_id = 2
    ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following table CREATE TABLE User ( email sysname NOT NULL, sign varbinary(256)
I have the following (abridged) DTO for registering a new user: [PropertiesMustMatch(Password, ConfirmPassword, ErrorMessage
i have following View where user has a table of products and i need
I have following two tables in the database. One table is person table and
I have following CSS: table tbody tr:last-child td { padding-top: 7px; border-bottom: 0; }
i have following tables T1 ==== ====== ID Desc ==== ====== 1 t1 2
I have the following very simple and (abridged) classes: // IEntry interface public interface
I have following table (SQL Server) Table name is LandParcels Blockid ParcelNo Stateorprivate ========================
Have following CF: create column family gr_ip2 with column_type = 'Standard' and comparator =
I have following method that I select all the ids from table and append

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.