Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Location
    Brighton, UK
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Quick COUNT() question

    The MySQL documentation says:

    COUNT(DISTINCT expr,[expr...])

    Returns a count of the number of different non-NULL values.
    How do i get it to INCLUDE null values? I am using COUNT with the DISTINCT bit as well, and i want the NULL rows to count as one as well.

    Thanks,
    Jack

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    what are you trying to count? Distinct tools for instance?

    If you have
    wrench, wrench, hammer, null, null, null, screwdriver


    and you are trying to count the distinct things then you have 3 tools.
    if you are trying to count the nulls in there as well each null is distinct from the other so you have six tools. Is that really what you want?

    In order to count nulls you need count(*) but of course that would include two counts for wrench.

  • #3
    Regular Coder
    Join Date
    Mar 2005
    Location
    Brighton, UK
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually ive realised i was trying to do the wrong thing and it works differently now. Thanks anyway.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •