?
Solved

sql server query

Posted on 2008-10-22
8
Medium Priority
?
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 37

Accepted Solution

by:
momi_sabag earned 800 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

764 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