I have 3 tables named person,person1, person2. All the 3 table has 2 columns name and phno. Now my requirement is, if i give any particular phno it has to show either yes or no for the corresponding table.
My sample table is :
Person Table:
Name phno
abc 1234
def 2345
ghi 3456
and person2 table is
Name phno
abc 1234
def 2345
ghi
and person3 table is
Name phno
abc
def 2345
ghi 3456
As you can see, the same name can contain phno in one table and not in the other table. The required output is like :
Output 1:
Phno person person2 person3
1234 yes yes no
Output 2:
phno person person2 person3
3456 yes no yes
I have tried something like this..
select a.phno,case when a.phno = '1234'then 'Y' else 'N' end as phone_number1,
case when b.phno = '1234' then 'Y' else 'N' end as phone_number2,
case when c.phno = '1234' then 'Y' else 'N' end as phone_number3
from person as a, person2 as b, person3 as c
where a.phno = '1234' and b.phno = '1234' and c.phno = '1234';
can anyone help me to improve this to achieve what I want.Thanks