p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   SQL Language (http://p2p.wrox.com/forumdisplay.php?f=100)
-   -   Need help : how to query multiple categories (http://p2p.wrox.com/showthread.php?t=37044)

will2kready January 10th, 2006 09:37 PM

Need help : how to query multiple categories
 

I have a structure tables that already run ads system for long time. When post an ad, it is only can choose single category. Now we are planning to make it in multiple categories, so one ad can have many categories.

Table XcCpClassifieds :

CadID (autonumber) | CadCatID (number) | CadTitle (text) | CadDesc (text) | CadCreated (date)

Because the CadCatID field is in number, so I try to add another table called multicat:

Table Multicat :

CadID | CadCatID

So when someone post an ad with multiple categories choosen, then it insert to Table XcCpClassifieds’s CadCatID field as 0, and insert all the categories id in Table Multicat , ex:

Table XcCpClassifieds :
CadID | CadCatID | CadTitle | CadDesc | CadCreated
235 | 0 | test | test | 01/11/2006

Table Multicat :
CadID | CadCatID
235 | 5
235 | 12
235 | 4

And when someone post ad ad with single category, then just insert to Table XcCpClassifieds ex:
Table XcCpClassifieds :
CadID | CadCatID | CadTitle | CadDesc | CadCreated
235 | 5 | test | test | 01/11/2006

Now my problem is, im getting difficult to display all the ads in each category, what is the query looks like, maybe using UNION ? or any other suggestion. Now the ads displayed for each category, the problem I have is when it read from XcCpClassifieds, found the cadCatID is 0. what sql statement to join these tables ? and display all the ads (single cat and multiple cat ads).im running in MSSQL database.Thanks a lot.





All times are GMT -4. The time now is 06:08 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.