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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:28:38+00:00 2026-05-19T10:28:38+00:00

I have four tables one is a master table that contains columns for EmployeeID,

  • 0

I have four tables one is a master table that contains columns for EmployeeID, VendorID and DriverID

Then I have corresponding tables for each of these: employees, vendors and drivers
and they all have similar columns like first name, last name, etc.

So, I want to be able to pull all records from my master table and have the corresponding first name and last based on whether the master record is an employee, vendor or driver.

A row in the master table would like this for an employee

EmployeeID = 352
VendorID = 0
DriverID=0

Vendor would look like

EmployeeID = 0
VendorID = 954
DriverID=0

etc.

Help?

  • 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-19T10:28:39+00:00Added an answer on May 19, 2026 at 10:28 am

    You could use UNION ALL:

    SELECT 'employee' AS src, EmployeeID AS ID, FirstName, LastName
    FROM mastertable
    JOIN employee
    ON mastertable.EmployeeID = employee.ID
    
    UNION ALL
    
    SELECT 'vendor' AS src, VendorID AS ID, FirstName, LastName
    FROM mastertable
    JOIN vendor
    ON mastertable.VendorID = vendor.ID
    
    UNION ALL
    
    SELECT 'driver' AS src, DriverID AS ID, FirstName, LastName
    FROM mastertable
    JOIN driver
    ON mastertable.DriverID = driver.ID
    

    This will work even if someone has more than one ID set (in this case they will get one row for each ID that is set).

    You might also want to consider if it would be worth changing your schema to make it easier to query. Could you move all the common columns into the master table? Then you would only need to write the following query to get what you want:

    SELECT ID, Type, FirstName, LastName, ...
    FROM mastertable
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have four different tables, one main SPECIAL table containing only id's that reference
i have four tables user-question contains two columns: questionID, userID, the questions that the
I have four divs that are each one column tables with many rows. They
I have a table with one column and four rows. Each tr has a
I have four tables each with its own form, all these table share same
I am wanting to have a view table that aggregates rows from four tables.
If I have four tables, each with four columns, which use the primary key
So I have four tables. Each table has a single id for the previous
I have four tables. Three of them are tables with one key and they
i have four tables like below in sql server 2008 : TABLE 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.