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
 SQL Server Development (2000)
 Help Getting subcategoryname from category table

Author  Topic 

megala
Starting Member

23 Posts

Posted - 2008-02-21 : 04:05:10
Hi I have 3 tables in my database.
1) photo
2) category
3) subcategory

in my photo table i save my subcategoryid which is tied to the category table.

What i need to do is get the all the subcategoryname from subcategory table where photo.subcategoryid='1' and photoid='2'.

I can actually get the value, but what i want is also to display all the other values in subcategory table that share the same categoryid for the particular photoid.

lets say my photoid is 1 and my subcategoryid is 2 , so when check in category table , the categoryid for subcategory 2 is 3. How can i display other subcategories which is the same as categoryid 3

i hope my question is clear. Please help me on this.

eg


quote:

category table
categoryid
1
2
3
4

subcategory table
subcategoryid
1
2
3
4

categoryid
1
1
2
2



visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-21 : 12:39:00
[code]SELECT s.*
FROM photo p
INNER JOIN category c
ON c.subcategoryid=p.subcategoryid
INNER JOIN subcategory s
ON s.categoryid=c.categoryid[/code]
Go to Top of Page
   

- Advertisement -