Returning values as field names
This isn't the easiest problem to describe but I'll do my best...
I have 3 tables, with the field names in brackets;
UserAccounts (ID, UserNick, Pass)
UserRoles (ID, Description)
UserAccountRoles (UserAccountID, UserRoleID)
I use these to define the roles of each user (and therefore the permissions they have) within my application. I want to construct a query to return each user in one column, followed by columns for each role containing a boolean value indicating whether or not they are in this role (i.e. whether a record exists in the UserAccountRoles table).
I can do something like this to get a list but it's not the most user friendly way of presenting it to the user:
SELECT UserAccounts.ID, UserAccounts.UserNick, UserRoles.Description FROM ((UserAccounts LEFT JOIN UserAccountRoles ON UserAccounts.ID = UserAccountRoles.UserAccountID) LEFT JOIN UserRoles ON UserAccountRoles.UserRoleID = UserRoles.ID) ORDER BY UserAccounts.UserNick
I generally get on pretty well with SQL but I can't even figure out where to get started with this one! Is it even possible? Any help greatly appreciated!