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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:57:53+00:00 2026-06-15T19:57:53+00:00

I have the following table structure: table: user user_id | join_date 101 | ‘2012-4-13’

  • 0

I have the following table structure:

table: user
user_id | join_date
    101 | '2012-4-13'
    102 |  '2012-6-4'
    103 |        NULL
    104 |        NULL

table: job
job_id | user_id
    20 |      101
    21 |      103

I want to return a single result set of user records that contains the following:

  1. The results of all users that have a match in the job table.
  2. The results of all users where the join_date is null, AND do not have a record in the job table.

Here is the result set of user_id’s I would like to see:

user_id
    101 <-- has a job
    103 <-- has a job
    104 <-- never joined, AND also does not have a job

Do I need to do this using Common Table Expressions or can I do this in a subquery?

Please note I’ve left out actual details for the sake of brevity. This is not a simple case of an inner join.

Here are each of my queries running separately:

THIS IS THE QUERY THAT RETURNS THE PROPER RESULT FOR #1

SELECT DISTINCT u.*   
FROM [user] u, job uj
WHERE u.user_id = uj.user_id

THIS IS THE QUERY THAT RETURNS THE PROPER RESULT FOR #2

SELECT DISTINCT u.*   
FROM [user] u  
FULL JOIN job uj ON u.user_id = uj.user_id   
WHERE u.join_date IS NULL AND uj.user_id 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-06-15T19:57:54+00:00Added an answer on June 15, 2026 at 7:57 pm

    This should do it:

    select u.user_id from [user] u
    left join job j on u.user_id = j.user_id
    where j.job_id is not null or (j.job_id is null and u.join_date is null)
    

    Edit:
    This is logically the same and “simpler” but the first way “reads” like the problem statement:

    select u.user_id from [user] u
    left join job j on u.user_id = j.user_id
    where j.job_id is not null or  u.join_date is null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table structure: ID, User_ID, DateTime Which stores a user id
I have table with following structure Whenever user click on checkbook and click on
I have an asp:table(table1), in a user control with following structure | Col2 |
I have a table with the following structure leave_id int(10) No user_id int(10) No
I have a table in the following structure... ID USER_ID INTEREST 1 290 soccer
I have the following table structure CREATE TABLE `table` ( `id` int(11) NOT NULL
I'm starting with yii. I have the following DB structure: Table: Rows: user [id,login,password,name,email]
I have the following table structure: ID | fname | lname | street |
I have the following table structure inside a view which gets displayed in the
I have the following table structure: ORGANIZATION_ID | Name | PARENT_ID -------------------------------------------------- 1 |

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.