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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:09:24+00:00 2026-06-16T00:09:24+00:00

I have the following schema: user — user_id | first_name full_time_job — ft_job_id |

  • 0

I have the following schema:

user -- user_id | first_name
full_time_job -- ft_job_id | user_id
part_time_job -- pt_job_id | user_id
internship -- internship_id | user_id

I’d like to write a query that returns all users that exist in any of the three job tables. What’s the best way to do this? I’d prefer to use LEFT JOINS over WHERE EXISTS if possible, but will be happy with the best working solution.

I do NOT want to return any users that exist in NONE of the three job tables.

  • 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-16T00:09:25+00:00Added an answer on June 16, 2026 at 12:09 am

    Using LEFT JOINs, you merely need to verify that user_id is NOT NULL in at least one of the tables:

    SELECT
      [user].user_id
    FROM
      [user]
      /* LEFT JOIN against each of the 3 tables */
      LEFT JOIN full_time_job ft ON [user].user_id = ft.user_id
      LEFT JOIN part_time_job pt ON [user].user_id = pt.user_id
      LEFT JOIN internship intern ON [user].user_id = intern.user_id
    WHERE
      /* And check that *any* of them has a non-null user_id */
      ft.user_id IS NOT NULL
      OR pt.user_id IS NOT NULL
      OR intern.user_id IS NOT NULL
    

    Best to fix the schema if possible…

    In the long run though, if possible these should all probably be combined into a single table that has a column indicating the job type, rather than 3 similar tables.

    Sample: http://sqlfiddle.com/#!2/2cd2c/1

    In the above example, users 5,6 don’t exist in any of the 3 tables.

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

Sidebar

Related Questions

I have a database schema that is similar to the following: | User |
Suppose you have the following schema (id, user_id , score). How can I take
I have the following (abridged schema) - 3 tables - user, job, job_type TABLE:
I have the following schema User: columns: id: type: integer primary: true name: string
I have a MySQL table with the following schema: +---------+---------+----------------------+------------+ | User ID |
I have the following existing DB schema, which I'd like to recreate with Java
I have a Rails application, I have the following DB schema: each User has
I have the following schema, which I use to ensure that a person's PhoneNumber
Suppose I have the following schema t = {name: 'John', reviews: [{sid: 1, comment:
I have the following XML Schema: <Root> <EventSet> <Event> <id> //random id </id> <time>

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.