How to get rows count in sql result with group by - mysql

I would like to know how is possible to get rows count in result of sql statement with group by. As I know count aggregation counts the result of grouped rows but I would like to know the count of all rows in result but without subselect. Does anybody know how PhpMyAdmin count rows returned by query with grouped rows? I think there is a special command for mysql but dont remember the name.

Related

Only returns 1 row?

Picture 1 is the table containing the data
Picture 2 is my command
Why is it only returning 1 row and not the same for all the subjectIDs?
How do I make it return a row for each subjectID?
Thanks
p.s Please keep things simple I need to do this with basic sql.
You are running an AVG command. This will aggregate the results, since an average has to be run on multiple rows of data.
If you want to have it grouped in a different way, you can do this with a GROUP BY clause. This will return a row for every distinct values for the column(s) specified in the GROUP BY clause, with the calculated average and so on.
It would look similar to the following:
SELECT subjectid, AVG(result)
FROM Results
GROUP BY subjectid

how to obtain the explain result in mysql by code?

I planned to use rows in the explain result in replace of count(*). but I cannot get the rows number by code.
I have tried to treat the result as a table and select rows from it but it didn't work.

COUNT returns total rows ignoring LIMIT in MySQL, why?

Today while I was writing a complex query, accidently I found that even I have set LIMIT in my query MySQL server returns the total number of rows for COUNT.
Example:
SELECT COUNT(*) FROM `log` LIMIT 10;
Output:
5219
But if I run the query without COUNT it returns only 10 rows. My question is,
Why does MySQL ignore LIMIT when the COUNT is present?
LIMIT is for returning a subset of the total results, in your case the result is only one line so no effect
The purpose of LIMIT clause to select a limited number of records whereas count is aggregate function, which will return result of aggregation. It won't make any sense to use LIMIT and COUNT together as LIMIT may return any random n records.

mysql count query gives 1

I mistakenly run query
SELECT count(*) table_name
to learn row count. It gives 1 as result. Do you know what is the meaning of this result "1"?
Thanks,
Simple.
The table contains 1 record.
Basically COUNT returns the number of records found on the table.
COUNT

Database count query returns different result to equivalent select

I have a query with few joins, on running it shows 11 records.
When I run its count query (removed fields from SELECT part and put COUNT(*) there) it returns different number, 16.
Why just converting to count query returns different count than its original query?
Either you have used Select Distinct when you are getting the number of rows 11 in result.
or
you are not using distinct in Count like Count(Distinct fieldname), so Count(*) is giving all the record count.
Most probably your join query returns the same rows twice or more. You can see what i mean by executing select * from... query