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
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

    Question need to add DISTINCT to SQL?!

    need to add: DISTINCT $tableName.booking_date

    to my following SQL line below:

    "SELECT COUNT(*) as num FROM $tableName WHERE booking_date BETWEEN '$from' AND '$to'"

    please help

  • #2
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    can anyone help here?

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    I'm sorry, the question doesn't make sense, to me.

    Are you saying you want a COUNT for each distinct booking_date??

    In that case, you don't want DISTINCT, you want GROUP BY:
    Code:
    $sql = "SELECT booking_date, COUNT(*) as num "
         . " FROM $tableName "
         . " WHERE booking_date BETWEEN '$from' AND '$to' "
         . " GROUP BY booking_date "
         . " ORDER BY booking_date';


  •  

    Posting Permissions

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