Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2011
    Posts
    5

    Unanswered: Assistance with Query

    I'm hoping someone can help me with a query that I'm trying to construct.

    I have two tables, bills and bill_items. The tables are shown below.

    BILLS
    -->bill_id
    -->bill_date
    -->customer_last

    BILL_ITEMS
    -->bill_id
    -->item

    Given the table data shown below:

    === bills ===
    1, 2011-01-25, doe
    2, 2011-01-27, doe

    === bill_items ===
    1, A001
    1, A002
    1, A003
    2, A001
    2, B004

    I would like to construct a query that produces the following output:

    Inv # | Date | Last Name | Items
    1 | 2011-01-25 | doe | A001 A002 A003
    2 | 2011-01-27 | doe | A001 B004

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT bills.bill_id
         , bills.bill_date
         , bills.customer_last
         , GROUP_CONCAT(bill_items.item
                    SEPARATOR ' ') AS items
      FROM bills
    LEFT OUTER
      JOIN bill_items
        ON bill_items.bill_id = bills.bill_id
    GROUP
        BY bills.bill_id
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Mar 2011
    Posts
    5

    Smile Worked Brilliantly

    Worked brilliantly. Thank you so much for the response!

Posting Permissions

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