Skip to content
Advertisement

How to write a select query that returns multiple results based on the booleans in one row (for spring security authorities query)?

I have a Java web app using Spring Security 5.

I’m using MySQL as the database.

The database table with users in it looks something like this:

Spring Security requires me to give it two queries … one to get the users, and one to get the user’s roles.

Typically the queries look like this:

However, my users and roles are in one table.

So, for my “authorities” query, is there a way to write an SQL query on my USERS table (above) that will give me a record for every “role” value that is 1 (true)? A result something like this:

Advertisement

Answer

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement