I made this solution but it continues not returning any value If the user not exists.
select case when TypeId = 1 then 1 when TypeId = 0 then 2 when count(1) < 1 then 3 end from Type where mail = 'firstname.lastname@example.org' group by Type
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.Sign up to join this community
Application would be much better place to deal with such cases as Aaron Bertrand said but you can do it with SQL as well .
select case when TypeId = 1 then 1 when TypeId = 0 then 2 end from Type where mail = 'email@example.com' UNION ALL SELECT 3 FROM DUAL WHERE NOT EXISTS (SELECT NULL FROM Type WHERE mail = 'firstname.lastname@example.org')
**Depends on RDMS you're using you may or may not need specify "FROM DUAL".