Follow up question for: Conditional row count across 4 tables
After getting some excellent help from 200_success, i managed to output the SUM()
total of my query using the following code:
get_results
returns standard mysqli_assoc_array
:
$row = $this->get_results($query);
$sum = $row[0];
foreach($sum as $sum) {
echo $sum;
}
Is this the best way to handle the result, are there any drawbacks / performance hits to doing it this way, how would you handle this querys result?
Query
$query = "SELECT SUM(inactive_count) AS inactive_count
FROM (
SELECT COUNT(article_active) AS inactive_count
FROM wcx_articles WHERE article_active = 0
UNION ALL
SELECT COUNT(video_active)
FROM wcx_videos WHERE video_active = 0
UNION ALL
SELECT COUNT(app_active)
FROM wcx_apps WHERE app_active = 0
UNION ALL
SELECT COUNT(link_active)
FROM wcx_links WHERE link_active = 0
) AS wcx_objects";
GROUP BY
clauses which I thought were needed when you are selecting an aggregate function likeSUM()
orCOUNT()
... \$\endgroup\$