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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-04-08 : 08:32:12
|
Tyron writes "Dear SQL teamI would like to perform a query on a table with following valuestable: qry_book_categoriesCategoryID Category BookID Book---------- --------- ------ ----1 Pets 1 Dog training2 Music 2 Piano lessons3 Training 1 Dog training1 Pets 1 Pigeons I would like to view books that must belong to categories I specify e.gSelect BookID where CategoryID=1 AND CategoryID=3The book Dog training should be returned since it belongs to both categories. I would very much appreciate your assistance.Thank you in advance.Tyron" |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-04-08 : 09:12:41
|
change your AND to OR.Go with the flow & have fun! Else fight the flow |
 |
|
|
Kaleem021
Starting Member
26 Posts |
Posted - 2005-04-08 : 09:30:08
|
| Select BookId from qry_book_categories t1 where CategoryId=1and (select count(*) from qry_book_categories where CategoryId=3 and BookId=t1.BookId) > 0*****************************************************************************Myth BreakerKaleem021@hotmail.comDoing Nothing Is Very Hard To Do, You Never Know When You Are Finished. |
 |
|
|
DustinMichaels
Constraint Violating Yak Guru
464 Posts |
Posted - 2005-04-08 : 09:32:57
|
| If possible you may want to normalize this table to eliminate some of the duplicate data.BookBookIDBookCategoryCategoryIDCategoryBookCategoryBookIDCategoryIDDustin Michaels |
 |
|
|
|
|
|