Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

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
0
dotnet0824
Asked:
dotnet0824
  • 3
  • 3
  • 2
1 Solution
 
momi_sabagCommented:
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
0
 
divyeshhdoshiCommented:
select *
from students s left outer join slot_table st on s.slot_id=st.slot_id
where t1.isActive=1
0
 
dotnet0824Author Commented:
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..
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
momi_sabagCommented:
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
0
 
dotnet0824Author Commented:
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
0
 
momi_sabagCommented:
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
0
 
divyeshhdoshiCommented:
may be there is no inactive students or you set isActive=1 for inactive students
0
 
dotnet0824Author Commented:
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
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now