Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2003
    Location
    Philippines
    Posts
    3

    Smile Unanswered: producing 0 output

    here's my query:

    SELECT pcategory.id, pcategory.name AS category_name,description, count(photos.category) AS num_of_items FROM photos, pcategory WHERE category = pcategory.id GROUP BY category_name ORDER BY pcategory.id ASC

    basically as you can see it matches the category id/# the a certain field that has that category id. unfortunately i couldn't get a return of 0 count to a certain field... i need to show that this certain category has 0 items, because i'm using this in a photo gallery where it has categories for the photos....the query above only returns counts that are >0

    hope you guys can help, thanks!!....btw, this is my first time to post here

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    select pcategory.id
         , pcategory.name  as category_name
         , pcategory.description
         , count(photos.category) as num_of_items 
      from pcategory
    left
      join photos
        on pcategory.id = photos.category
    group
        by pcategory.id
         , pcategory.name
         , pcategory.description 
    order
        by pcategory.id asc
    rudy
    http://r937.com/

  3. #3
    Join Date
    Mar 2003
    Location
    Philippines
    Posts
    3
    great!!!! superb.....it works like a charm..heheh...thank you so much bro!!!!!...but is it ok if you could shortly explain the part you started using JOIN and how was it able to produce 0?? =) thanks alot again!!!

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002

  5. #5
    Join Date
    Mar 2003
    Location
    Philippines
    Posts
    3
    again.....thanks so much...you really did a tremendous help!!!...i really appreciate the resource n help... =)

Posting Permissions

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