Here is the query:
select IF ((t1.emp_id IS NOT NULL), t2.username, '')
from t1, t2
where t1.user_id = "285" AND t2.id = t1.emp_id
It works fine, but if t1.emp_id is NULL it will not return result because of this part AND t2.id = t1.emp_id but this part secure me that I will get exact t2.id if t1.emp_id is not NULL. Is there a way to handle it ?
The idea is if t1.emp_id is not null then to return t2.username based on relation t1.emp_id = t2.id but in this case when t1.emp_id is null it doesn't return result, because of last part of query. If I remove last part it will not returns me exact row from t2.
JOINsyntax.