Solved

sql server query

Posted on 2008-10-22
8
203 Views
Last Modified: 2012-05-05
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
Comment
Question by:dotnet0824
  • 3
  • 3
  • 2
8 Comments
 
LVL 37

Expert Comment

by:momi_sabag
ID: 22775313
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
 
LVL 6

Expert Comment

by:divyeshhdoshi
ID: 22775329
select *
from students s left outer join slot_table st on s.slot_id=st.slot_id
where t1.isActive=1
0
 

Author Comment

by:dotnet0824
ID: 22775416
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 37

Accepted Solution

by:
momi_sabag earned 200 total points
ID: 22775436
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
 

Author Comment

by:dotnet0824
ID: 22775441
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
 
LVL 37

Expert Comment

by:momi_sabag
ID: 22775483
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
 
LVL 6

Expert Comment

by:divyeshhdoshi
ID: 22775520
may be there is no inactive students or you set isActive=1 for inactive students
0
 

Author Comment

by:dotnet0824
ID: 22775602
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question