I have a directory table in a MySQL database that contains user ID’s, user types, and assorted other directory information. There are two types of users: employee and student. The primary key is (userID, userType), so any given user can have an employee record and a student record (in the event that they are both an employee and a student).
I would like to perform queries on a subset of this table, so that:
- If a user has only an
employeexor astudentrecord, that record is used, and - If a user has both an
employeeand astudentrecord, theemployeerecord is used and thestudentrecord is ignored
I will not need to include an ORDER BY clause in the queries, but they can include rather complicated WHERE clauses (including queries on userType itself).
Ideally, I would like to do this without having to create extra tables or views, but if an extra view is necessary I can ask the sysadmin for CREATE VIEW permissions.
Didn’t actually test it, but something like this should work:
In plain English: select all employees (left of OR) and all students for which there are no corresponding employees (right of OR).