In a database a certain user has four levels of access to data. Each level he has, is stored in a database record with the userID and the access level as a string. (This is not good design, but this is what I have to work with.) When a person has a certain level of access, it automatically has all lower levels. So if a person has level 3, there are three database records for it. The strings are abbreviations of what the level allows, so, it is impossible to simply use the MAX-function
Now I have to write an other program, using the same database and I want to write an SQL-statement that only gets the highest level per person, without having to change the database (so the other program won’t crash).
The database is MySQL.
Create a temporary table that can join to the user table and associates the access levels (in strings) to integers. You can then use MAX on that integer column.