Question : Problem with MYSQL_QUERY AN UNION ALL

Greetings, why does the following query return the following error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource


$MostAdsinCities=mysql_query("SELECT city AS mostCity, COUNT(active) AS mostincity FROM table1 WHERE active='1' UNION ALL SELECT city AS mostCity, COUNT(active) AS mostincity FROM table2 WHERE active='1' UNION ALL SELECT city AS mostCity, COUNT(active) AS mostincity FROM table3 WHERE active='1' GROUP BY mostCity ORDER BY mostincity DESC LIMIT 10");

// CHECK THE NUM ROWS
$NumMostAdsinCities=mysql_num_rows($MostAdsinCities);

Answer : Problem with MYSQL_QUERY AN UNION ALL

You could try something like

$MostAdsinCities=mysql_query("SELECT mostCity, SUM(mostincity) as mostincity FROM (SELECT  city AS mostCity, COUNT(active) AS mostincity FROM table1 WHERE active='1' GROUP BY mostCity UNION ALL SELECT city AS mostCity, COUNT(active) AS mostincity FROM table2 WHERE active='1' GROUP BY mostCity UNION ALL SELECT city AS mostCity, COUNT(active) AS mostincity FROM table3 WHERE active='1' GROUP BY mostCity) X GROUP BY mostCity ORDER BY mostincity DESC LIMIT 10");
Random Solutions  
 
programming4us programming4us