How can I select the count from an inner join with grouping?
SELECT COUNT(table1.act) FROM table1
INNER JOIN table2 ON table1.act = table2.act
GROUP BY table1.act
This will return the count of act's found in table2.
Adding
SELECT table1.act, COUNT(table1.act) AS test
Returns
act test
------- ----
17682 3
17679 3
17677 3
11636 1
11505 1
I want to receive the count of act's found total.
So I want to get 5. Can you help?
SQL SUM() and COUNT() with inner join The data from a subquery can be stored in a temporary table or alias. The data of these temporary tables can be used to manipulate data of another table. These two tables can be joined by themselves and to return a result. Here is a slide presentation of all aggregate functions.
Show activity on this post. $query_string = ' SELECT groups. userGroupID, userGroup, count(users. userGroupID) AS howMany FROM groups_table AS groups JOIN users_table AS users ON users.
COUNT(*) returns the number of rows in a specified table, and it preserves duplicate rows. It counts each row separately. This includes rows that contain null values.
To achieve this for multiple tables, use the UNION ALL. select sum(variableName. aliasName) from ( select count(*) as yourAliasName from yourTableName1 UNION ALL select count(*) as yourAliasName from yourTableName2 ) yourVariableName; Let us implement the above syntax.
You can wrap that query into another query:
SELECT COUNT(*) FROM (
SELECT COUNT(table1.act) AS actCount FROM table1
INNER JOIN table2 ON table1.act = table2.act
GROUP BY table1.act
) t
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With