Solved

sql server query

Posted on 2008-10-22
8
200 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
 
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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with simplifying SQL 6 51
Upgrading SQL Server Management Tools 7 36
Max Consumption Rate (MCR) 3 34
TSQL DateADD update Question 4 31
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now