I have two tables one with employee information in people_table and one with the phone no. of these employees. Now the phone_table can have multiple entry for a particular employee with different types like W1-->Work,M-->Mobile,H1-->Home. Now i want to wriet query such that if W1 is enetered then no other phone type should be fetched. If W1 is not enetered then M should be checked and query should fetch mobile number instead(so on and so forth) so basically i have to use if and else in select statement . I cannot write a function for this as per requirement.
I tried using Case and when like follows :-
select emp_num, emp_name,ph_no,ph_type,
case
when ph_type='W1'
then ph_no
when ph_type='M'
then ph_no
from people_table pt ,phone_table ppt
where pt.person_id=ppt.person_id
But this is also returning the same output. that is if an wmployee has w1 no. and M no. it will return both.. but it should fetch W1 no. only and not M