SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2009
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Expecting records are not coming thru this query

    SELECT a.fname, a.lname, p.id, p.description, p.image, p.totalamount, p.neededamount, SUM( d.amount ) AS received_amount
    FROM jos_sahayata_patients AS p
    LEFT JOIN jos_sahayata_address AS a ON a.type_id = p.id
    LEFT JOIN jos_sahayata_donations AS d ON d.patient_id = p.id
    WHERE a.type = 'p'
    AND p.approve =1
    GROUP BY d.amount
    ORDER BY p.id DESC
    LIMIT 0 , 30

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    What are you expecting, and what are you getting? Try explaining in your own words, and maybe add a data example.

    Anyway, putting this
    Code:
    a.type = 'p'
    in the WHERE clause, the LEFT JOIN of jos_sahayata_address has become an INNER JOIN. If you really need the LEFT JOIN, put that condition in the ON clause.

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2009
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have got 3 tables
    1)jos_sahayata_patients where i have patient information
    2)jos_sahayata_address where i have patient address
    3)jos_sahayata_donations where donations to the patients are saved

    now i want to display all the patients with their address and the sum of the donations each patients received.

    if particular patient not received any amount(donations) his amount should be null.

    but i am not getting all the patients records by the above query

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Don't group by d.amount, instead group by p.id

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2009
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    @guido2004

    My problem solved.

    Thank u very much.


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
  •