简体   繁体   中英

MySQL Coalesce() function - Determining which field was non-null

I am writing a query that fetches the permissions for a user on our website. It first checks to see if there are any overrides for the permissions, then checks the permissions for the users role on the website, and if those are null it's defaulted to 0 (AKA no permission.. the other values would be >1). I figured coalesce() would be the best choice here as I could do something like

coalesce(override, role, 0);

Where override and role would be the fields in the database.

However, if it was indeed an override permission, I need to know because I display an icon indicating it as such. Is there any way I could determine this in a clean manner?

为布尔值添加一个单独的带有布尔值的列。

select coalesce(override,role,0), (override is not null) as override_enabled

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM