Jump to content
xisto Community
TavoxPeru

Count The Number Of Records Of A Table Group By A Foreign Key

Recommended Posts

how do i count the number of records of a table group by a foreign key??? Here are my tables:a. table situation:CREATE TABLE `situation` ( `id_situation` tinyint(3) NOT NULL auto_increment, `situation` varchar(20) NOT NULL default '', PRIMARY KEY (`id_situation`)) TYPE=MyISAM ;b. table documents:CREATE TABLE `document` ( `id_document` int(8) unsigned NOT NULL auto_increment, `id_situation` tinyint(3) unsigned NOT NULL default '1', `regdate` date NOT NULL default '0000-00-00', `notes` text NOT NULL, PRIMARY KEY (`id_document`)) TYPE=MyISAM ;What i need is to show for each record of the table situation how many records exists in the table documents, i try this SELECT:select situation.id_situation, situation.situation, count(document.id_situation) as totdocs from situation, documents where situation.id_situation=document.id_situation group by situation.id_situation order by situation.situation;but it does not show the correct values.Best regards,

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.