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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.