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?
You could use UNION ALL:
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: