how count work at backend Level.

  • Hi guys,

    If i am putting count(any integer) like count (5) .

    It will count all the rows of table and showing same result if we change other value stilll resull result is same.

    How count work at backend level that i dont understand ?

  • Hi

    welcome to SSC......

    your question isnt clear to me...suggest you read following article and post back.

    http://spaghettidba.com/2015/04/24/how-to-post-a-t-sql-question-on-a-public-forum

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

  • COUNT(<any constant>) means count the rows in the resultset. If you say COUNT(<any constant>) FROM Table, then it returns count of the rows in the table.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • That any integer is just a placeholder. As you've already noticed, you'll get the same result whatever argument you put in there. What you do have to be careful of is putting a column name as an argument. If you do that, you'll get a count of non-null values in that column, which won't necessarily be the same as the number of rows.

    John

  • Thanks john

  • John Mitchell-245523 (1/11/2016)


    That any integer is just a placeholder. As you've already noticed, you'll get the same result whatever argument you put in there. What you do have to be careful of is putting a column name as an argument. If you do that, you'll get a count of non-null values in that column, which won't necessarily be the same as the number of rows.

    John

    I would phrase it slightly differently. COUNT() will count the non-null instances of the given expression for each row. Integer constants will never be NULL, so this is equivalent to counting every row.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • You've received an explanation on why your code isn't behaving as you expected.

    Maybe now you could explain what you're trying to do and get the way to do it correctly.

    Unless you're fine with the previous answers.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply