I know that I am missing something, I have tried several different ways but I am overlooking (or trying too hard). Can someone please tell me where I am wrong on this SQL?
SELECT id,
COUNT(id) AS dupBlocks
FROM tbl_duplicates8 INNER JOIN (
tbl_accounts8,
tbl_delaccounts,
tbl_bad_bots,
tbl_log,
tbl_ipban,
tbl_ipban8
) ON (
tbl_accounts8.SUM(num_attacks) AND
tbl_delaccounts.SUM(noattacks) AND
tbl_bad_bots.COUNT(id) AND
tbl_log.COUNT(id) AND
tbl_ipban.COUNT(txt_ip) AND
tbl_ipban8.COUNT(ip)
);
I did notice this MySQL Join two tables count and sum from second table but it gives me a null on return.
Any help would be appreciated.
To further the question for a better answer, this is what I am currently doing:
$statsresults['newIPBan'] = $db->query("SELECT COUNT(ip) AS newIPBan FROM tbl_ipban8;");
$statsresults['oldIPBan'] = $db->query("SELECT COUNT(txt_ip) AS oldIPBan FROM tbl_ipban;");
$statsresults['log_blocks'] = $db->query("SELECT COUNT(id) AS logBlocks FROM tbl_log;");
$statsresults['badbots'] = $db->query("SELECT COUNT(id) AS badBots FROM tbl_bad_bots;");
$statsresults['del_num_attacks'] = $db->query("SELECT SUM(noattacks) AS deltotalattacks FROM tbl_delaccounts;");
$statsresults['num_attacks'] = $db->query("SELECT SUM(num_attacks) AS totalattacks FROM tbl_accounts8;");
$statsresults['dup_blocks'] = $db->query("SELECT COUNT(id) AS dupBlocks FROM tbl_duplicates8;");
Which will return this:
| ['newIPBan0newIPBan'] = String(6) "289033"
| ['oldIPBan0oldIPBan'] = String(6) "125723"
| ['log_blocks0logBlocks'] = String(4) "6481"
| ['badbots0badBots'] = String(5) "15310"
| ['del_num_attacks0deltotalattacks'] = String(9) "119494860"
| ['num_attacks0totalattacks'] = String(8) "25286478"
| ['dup_blocks0dupBlocks'] = String(6) "179916"
So right now it is calling the database 7 times to get each sum or count. I was hoping to change that to 1 database call and returning the sum of them all.
JOINtbl_duplicates8to 6 other tables and then return theSUMandCOUNTof specific fields? As it stands, the Sql query doesn't make much sense.