2
votes

I have three tables

Table1 Table2 and Table3.

Table1 having column ID. Table2 having column names ID,Name. Table three having column name Name.

Now i want to retrive ID from table1 which is there in Table2 by so that the name associated with ID in table to should be in Table3.

Table1.ID=Table2.ID(Table2.Name=Table3.Namw).

Without using IN operator.Only joins.

2

2 Answers

5
votes
select table1.id, table2.name
from table1
join table2 on table2.id = table1.id
join table3 on table3.name = table2.name
1
votes
select distinct t1.ID
from Table1 t1
    ,Table2 t2
    ,Table3 t3
where t1.ID = t2.ID
  and t2.Name = t3.Name
;

or

select t1.ID
from Table1 t1
where exists (
  select 1
  from Table2 t2
      ,Table3 t3
  where t1.ID = t2.ID
    and t2.Name = t3.Name
);