The site I’m working on has 3 different types of users: admin, applicants, reviewers. Each of these groups will have some basic info that will need to be stored (name, id, email, etc) as well as some data that is unique to each. I have created a users table as well as a table for each of the specific groups to store their unique data.
- users: id, f_name, l_name, email, user_type
- users_admin: id, user_id, office, emp_id
- users_applicant: id, user_id, dob, address
- users_reviewer: id, user_id, active_status, address, phone
If a user with user_type of “1” (applicant) logs in I will need to JOIN to the users_applicants table to retrieve their full record. I tried using a UNION but my tables have vastly different columns.
Is there a way to, based on a user’s type, write a conditional query that will JOIN to the correct table? Am I going about this completely the wrong way?
Thank’s in advance for your help!
Well, in the end your tables are already flawed. Why even have a table for each type? Why not put all those fields into the
userstable, or maybe auser_detailstable (if you really want an extra table for non-general data fields)? Currently, you’re actually creating 4 independent user tables from a relational point of view.So why do the type-tables have a surrogate key? Why isn’t the
user_idalready the (only) primary key?If you changed that, all you would need is the user id to retrieve the data you want, and you’ve already got that (or you wouldn’t even be able to retrieve the user type).