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 2005 Forums
 Transact-SQL (2005)
 Joining 2 tables on more than one category

Author  Topic 

designedit
Starting Member

1 Post

Posted - 2007-10-01 : 06:43:45
I think this question will be very easy for someone. I wondered what the "standard" way to do it is please?

From TableA and TableB below (joined by BookID) I would like to select books which are in specific categories. I can see how to do this if I'm just selecting from one category. But how is it done for more than one category? For example, I would like to select all books once which are in both catID 23 AND catID 24, thus having a result set of:

1 Trees
4 Cats

These are the only books in both categories.



TableA

BookID Title
1 Trees
2 Gardens
3 Dogs
4 Cats


TableB

ID BookID CatID
1 1 23
2 1 24
3 1 28
4 2 23
5 3 54
6 2 12
7 3 24
8 4 23
9 2 67
10 4 24

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-01 : 07:02:46
See this topic
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=90177



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -