I have 2 tables,
Users
- username PK
- nickname
Permissions
- username FK to Users
- permission_text
Given a username
, Is it possible to return 1 row with all the permissions and user details?
I can think of two methods, Method 1 is to SELECT * FROM permissions WHERE username = <username>
and do another query for SELECT * FROM users WHERE username = <username>
.
Method 2 is to join both table and use the first row for user details and a loop to get permissions from the rest of the row.
I don't feel both method is very clean in term of relational database. What kind of query should I do so that I can get user details and array of permissions?