By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,943 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,943 IT Pros & Developers. It's quick & easy.

Using Count on 'Joined' tables

P: n/a
Hi there

I have two tables, pages and sections, of which pages are a subset of
sections. I'm listing out the sections in a list and want to include a
COUNT of how many pages each section has within it.

Pages contain a 'sectionid' field to join it to the 'id' in the seciton
table but im unsure how to join, and group to get a count of the
number of pages in each section (i.e. in each result row)

If anyone can point me in the right direction, id be eternally greatful
:-)

Jul 12 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

danny_m wrote:
Hi there

I have two tables, pages and sections, of which pages are a subset of
sections. I'm listing out the sections in a list and want to include a
COUNT of how many pages each section has within it.

Pages contain a 'sectionid' field to join it to the 'id' in the seciton
table but im unsure how to join, and group to get a count of the
number of pages in each section (i.e. in each result row)

If anyone can point me in the right direction, id be eternally greatful
:-)
not sure if this is what you need exactly, but if your running two
separate mysql queries on the same page just:

$totalrows = mysql_num_rows($query1)+mysql_num_rows($query2);

Flamer.

Jul 12 '06 #2

P: n/a
flamer di******@hotmail.com wrote:
danny_m wrote:
Hi there

I have two tables, pages and sections, of which pages are a subset of
sections. I'm listing out the sections in a list and want to include a
COUNT of how many pages each section has within it.

Pages contain a 'sectionid' field to join it to the 'id' in the seciton
table but im unsure how to join, and group to get a count of the
number of pages in each section (i.e. in each result row)

If anyone can point me in the right direction, id be eternally greatful
:-)

not sure if this is what you need exactly, but if your running two
separate mysql queries on the same page just:

$totalrows = mysql_num_rows($query1)+mysql_num_rows($query2);

Flamer.
the syntax will be along the lines of:

select s.section, sum(p.page) from sections s
left join pages on p.section_id = l.section_id
group by section_id

Jul 12 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.