Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SQL with a BackReference...

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-08-08 : 07:42:13
Sujit writes "I have a table 'tblClassTeacher' which relates a Class [ClassId] to one or many Teachers [TeacherId]. When given some TeacherIds as input, I want to be able to find out which Classes are common to those.
e.g. ClassId TeacherId
----------------------------------
1 1
1 2
1 3
2 2
2 3
4 3
5 4
----------------------------------
From above table, if input teachers are [2,3], I should be able to get classes 1 & 2. Input teacherId String may vary.

Can it be done in one single Sql Statement?

Thank you.

Sujit."

KenW
Constraint Violating Yak Guru

391 Posts

Posted - 2006-08-08 : 12:49:07
Sujit,


SELECT ClassID FROM tblClassTeacher WHERE TeacherID IN ( 2, 3 )


Ken
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-08-08 : 13:27:24
Learn SQL

http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp




Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -