I have the following table pet
in the database menagerie
:
+--------+-------------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+--------+-------------+---------+------+------------+------------+
| Tommy | Salman Khan | Lebre | NULL | 1999-01-13 | 0000-00-00 |
| Bowser | Diane | dog | m | 1981-08-31 | 1995-07-29 |
+--------+-------------+---------+------+------------+------------+
Now If I run the following query:
select owner, curdate() from pet;
I get the following output:
+-------------+------------+
| owner | curdate() |
+-------------+------------+
| Salman Khan | 2016-09-12 |
| Diane | 2016-09-12 |
+-------------+------------+
The output show all the values of owner
, and the value returned from curdate()
in each row.
Now if I run the following query:
select owner, count(*) from pet;
I get the following output:
+-------------+----------+
| owner | count(*) |
+-------------+----------+
| Salman Khan | 2 |
+-------------+----------+
My question is what is the difference between curdate()
and count()
function which makes MySQL
to output the second owner
Diane in the first example?
cmd
. – Hurlowgroup by
:p – SosONLY_FULL_GROUP_BY
see dev.mysql.com/doc/refman/5.7/en/group-by-handling.html – Plod