bdalina bdalina - 4 months ago 20
MySQL Question

MySQL query: select all active in a table but accept an inactive which id = 1

I know this one won't work but i give it a try, using union on the same table.

select `sys_id`,`username`,`status`
from user_tbl
WHERE sys_id=1
SELECT `sys_id`,`username`,`status`
from user_tbl
WHERE status ='active'
ORDER by sys_id

another try

select `sys_id`,`username`,`status`
from user_tbl
WHERE status='active' || sys_id=1
ORDER by sys_id

Is it possible?

all your selection is active but one item is inactive with an specified Id

1 | inactive
2 | active
3 | active
4 | active


All inactive OR (inactive with id 1) can be achieved like this:

select `sys_id`,`username`,`status` from user_tbl WHERE status='active' or
(status='inactive' and sys_id=1) ORDER by sys_id