Link to home
Start Free TrialLog in
Avatar of dotnet0824
dotnet0824

asked on

sql server query

i have 2 tables

student_ID   IsActive         slotID
  1       0                       1
  2                 1                  <NULL>
  3                 1                    2
  4                 1                    1
  5                 1                    <null>

Slot Table  
Slot_ID desc
  1     AB
  2     CD

I want to have all the students who r ACTIVE(ie 1) along with their Slot Description by joining 2 tables
Avatar of momi_sabag
momi_sabag
Flag of United States of America image

select t1.student_id, t2.desc
from students t1 inner join slot_table t2 on t1.slot_id = t2.slot_id
where t1.isActive=1
Avatar of divyeshhdoshi
divyeshhdoshi

select *
from students s left outer join slot_table st on s.slot_id=st.slot_id
where t1.isActive=1
Avatar of dotnet0824

ASKER

select *
from students s left outer join slot_table st on s.slot_id=st.slot_id
where t1.isActive=1

this statements shows even Inactive students too..
ASKER CERTIFIED SOLUTION
Avatar of momi_sabag
momi_sabag
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the statement was wrong it should be

select *
from students s left outer join slot_table st on s.slot_id=st.slot_id
where s.isActive=1

But it still shows inactive students too
that is impossible , but you can try this
with a as (select *
from students s left outer join slot_table st on s.slot_id=st.slot_id)
select * from a
where s.isActive=1
may be there is no inactive students or you set isActive=1 for inactive students
sorry
I used wrong clause AND (I should be using where)
select *
from students s left outer join slot_table st on s.slot_id=st.slot_id
AND s.isActive=1

Thanks