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
employee
xor astudent
record, that record is used, and - If a user has both an
employee
and astudent
record, theemployee
record is used and thestudent
record 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.