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 Query

Author  Topic 

ssd_123
Starting Member

2 Posts

Posted - 2004-09-09 : 09:46:06
Hello,
I have a table as shown below. I need to write a sql query that tells
me what courses are common between Tom and Jim.

Name CourseID
-------------
Tom 1
Tom 2
Tom 3
Jim 1
Jim 3
Jim 4


Output needs to something like:

CourseID
--------
1
3

Appreciate all your help.
Thanks, Subhash

mr_mist
Grunnio

1870 Posts

Posted - 2004-09-09 : 09:54:01
Something like

SELECT distinct a.courseid from yourtable a
INNER JOIN yourtable b
ON a.courseid = b.courseid
and a.name <> b.name


-------
Moo. :)
Go to Top of Page

ssd_123
Starting Member

2 Posts

Posted - 2004-09-10 : 11:28:56
Perfect! Thanks
Go to Top of Page

DustinMichaels
Constraint Violating Yak Guru

464 Posts

Posted - 2004-09-10 : 11:38:44
Sounds like a homework question.
Go to Top of Page
   

- Advertisement -