#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    16
    Rep Power
    0

    What will be the difference in output of these 2 MySQL Queries


    There is a column Salary in a Table EMPLOYEE. The following two statements are giving different outputs. What may be the possible reason?

    SELECT COUNT(*) FROM EMPLOYEE;

    SELECT COUNT(SALARY) FROM EMPLOYEE;

    This question asked in exam but I am not getting any difference even if I left salary of 1 employee blank
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    16
    Rep Power
    0

    YES I got answer


    YES I got answer
    If salary column is defined as NULL and then if any employee's salary is missing then count will skip those null valued record. I got this from http://cbsecsnip.in
  4. #3
  5. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,126
    Rep Power
    9398
    The manual is always a good place to look for information about a function.
    COUNT(expr)

    Returns a count of the number of non-NULL values of expr in the rows retrieved by a SELECT statement. The result is a BIGINT value.

    COUNT() returns 0 if there were no matching rows.

    Code:
    mysql> SELECT student.student_name,COUNT(*)
        ->        FROM student,course
        ->        WHERE student.student_id=course.student_id
        ->        GROUP BY student_name;
    COUNT(*) is somewhat different in that it returns a count of the number of rows retrieved, whether or not they contain NULL values.

IMN logo majestic logo threadwatch logo seochat tools logo