SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Dublin
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help needed to formulate a query

    Hi. Please could someone help me formulate a query to find all invoices for a patient.



    I have a patient table with patient_id

    I have an appointment table with appointment_id and patient_id

    I have an invoice table with invoice_id and appointment_id and fee




    Ideally I would also like to be able to get the sum of fees for a patient

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,095
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Code MySQL:
    SELECT
       c.client_id
     , SUM(i.fee)
    FROM
      client c
    INNER JOIN
      appointment a
      ON a.client_id=c.client_id
    INNER JOIN
      invoice i
      ON i.appointment_id=a.appointment_id
    GROUP BY
      c.client_id

    (untested)
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Tags for this Thread

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
  •