|
Mysql nested query help!
I need help in following query.
I am creating a database for Library listing for my college.
There are categories , sub - categories, sub sub - categories and so on.
What i want is what is similar at hotscripts.com . In PHP category, it shows number of listings inside it. Similarly, i wanted a mysql query which would directlt provide me number of listings inside it.
I have 3 tables
_______________________
One : stores the book categories
catid -> every book category has an unique ID
superset -> stores the parent category
For Ex.: If Entertainment category has catid = 10
then Sports category which belongs to Entertainment category has superset = 10
`category` (
`catid` bigint(6) NOT NULL default '0',
`name` varchar(60) NOT NULL default '',
`description` varchar(255) NOT NULL default '',
`superset` bigint(6) NOT NULL default '0',
`addable` tinyint(1) NOT NULL default '1',
UNIQUE KEY `catid` (`catid`)
) TYPE=MyISAM COMMENT='listing of all categories ';
_______________________
Two : Links the listings to the category they belong to.
`list_cat` (
`listid` bigint(6) NOT NULL default '0',
`catid` bigint(6) NOT NULL default '0'
) TYPE=MyISAM COMMENT='shows which listing is in which category';
_______________________
Three : Listing description.
`listing` (
`title` varchar(50) NOT NULL default '',
`listid` bigint(6) NOT NULL default '0',
PRIMARY KEY (`listid`)
) TYPE=MyISAM COMMENT='listing details';
I can do that using PHP loops , but it takes up lot of processor time and makes the local server slow. I guess this can be made easier of the server using some MYSQL command itself.
If someone could help, it would be very greatfull.
|