rcorrigal Posted December 9, 2010 Share Posted December 9, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/221158-trying-to-count-multiple-tables-how-do-i-make-this-work/ Share on other sites More sharing options...
fenway Posted December 10, 2010 Share Posted December 10, 2010 I suppose you could simply add them as scalar subqueries.... Quote Link to comment https://forums.phpfreaks.com/topic/221158-trying-to-count-multiple-tables-how-do-i-make-this-work/#findComment-1145206 Share on other sites More sharing options...
jdavidbakr Posted December 13, 2010 Share Posted December 13, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/221158-trying-to-count-multiple-tables-how-do-i-make-this-work/#findComment-1146911 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.