Jump to content

Trying to count multiple tables, how do I make this work...


rcorrigal

Recommended Posts

I'm trying to count from multiple tables, how do I make this work... This is what I have so far. With one table it works no problem, when I add another it doesn't. If this can be done without multiple queries it would help a lot too.

 

<? echo mysql_result(mysql_db_query('DBNAME', "SELECT COUNT(*) FROM TABLE1, TABLE2 WHERE conditions here"),0);?>

 

Any help would be greatly appreciated.

Link to comment
Share on other sites

I usually approach this type of a query by doing "select *" instead of "select count(*)" and get my joins worked out.  Using "select  *" in phpMyAdmin gives me the ability to see what rows are duplicates and usually clues me in to any missing WHERE conditions.  Once that query returns the rows you want to count, change "select *" to "select count(*)".

 

if your tables have appropriate keys linking them together you shouldn't have any problem doing that in one query.  Most likely there's something wrong in your WHERE clause to join the two tables together.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.