1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

Why difference between count(*) and count(*)

Discussion in 'SQL PL/SQL' started by Aruna Sameera, Feb 25, 2017.

  1. Aruna Sameera

    Aruna Sameera Active Member

    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    55
    Location:
    Singapore
    I have employee table which contain employee details. When i tried with below it gives me different couts

    1) select count(*) emp_count,
    count(department_id) nut_null_dept_id
    from employees;
    e is difference for those values ?
    i am getting emp_count=107 and nut_null_dept_id=106 . why ther
     
    Last edited: Feb 25, 2017
  2. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,619
    Likes Received:
    364
    Trophy Points:
    1,430
    Location:
    Aurora, CO
    COUNT(*) does not count NULLvalues; count(*) counts all rows and a r0w has at least ONE not null value.
     
  3. krasnoslobodtsev_si

    krasnoslobodtsev_si Forum Genius

    Messages:
    774
    Likes Received:
    147
    Trophy Points:
    830
    Location:
    Russian Federation
    http://docs.oracle.com/database/122/SQLRF/Aggregate-Functions.htm#SQLRF20035
     
  4. SujitKumar

    SujitKumar Active Member

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    55
    Location:
    Hyderabad
    COUNT(*) will count the number of rows, while COUNT(expression) will count non-null values in expression and COUNT(column) will count all non-null values in column. Since both 0 and 1 are non-null values, COUNT(0)=COUNT(1) and they both will be equivalent to the number of rows COUNT(*)
    oracle