SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member idimmu's Avatar
    Join Date
    Dec 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Count related records, but show records with NO related records also

    cl_items
    ========
    it_id (pk)
    it_ownerid
    it_name

    cl_offers
    ========
    off_id (pk)
    off_itid (fk) -> to it_id
    off_whoid

    My query needs to output ALL of the records in cl_items AND still show how many offers are on each item (from cl_offers)

    I can't get what I want through the GROUP BY because I want to show the records in cl_items which DO NOT have any offers on them yet also.

    Is there any way to do this with mysql only?

  2. #2
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    you need a LEFT OUTER JOIN. ever used one of those before?

  3. #3
    SitePoint Member idimmu's Avatar
    Join Date
    Dec 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've used LEFT JOIN but nothing with OUTER...

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by idimmu View Post
    I've used LEFT JOIN but nothing with OUTER...
    you're in for a pleasant surprise then



    the keyword OUTER is optional

    see Getting a count of zero for unmatched rows
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Member idimmu's Avatar
    Join Date
    Dec 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thank you much! seems strange to me that I've been trying to do this for about 5 hours now, and you tell me to do something that (I thought) I've already tried and now it WORKS! wow.


Bookmarks

Posting Permissions

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