CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2010
    Posts
    0

    Joining 3 tables - It's an EMERGENCY!!!

    So...

    I have 3 tables:

    TABLE: Sales
    Attributes: Sale_id, employee_id, customer_id, date_sale, amount, quantity

    TABLE: Products
    Attributes: They're too many. Let's consider just product_id, product_name

    TABLE: Gets (it's actually a relationship between Sales and Products)
    Attributes: sale_id, product_id, qantity



    I'm making a query in Sales that shows, among other stuff, the actual NAME of the product that is being sold... I managed to show the employee and customer names, but not the product_name, because I don't have any product_id in Sales table, I don't know how to relate them.

    This is what I have so far, showing everything I need, except for the product_name.

    select
    sales.data_sale as "Date",
    a.person_name as "Employee",
    b.person_name as "Client",
    sales.quantity as "Quantity",
    sales.amount as "Total ()"
    from person a, person b, sales
    where sales.employee_id = a.person_id and sales.customer_id = b.person_id

    Any help please? It's kind of urgent...

  2. #2
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: Joining 3 tables - It's an EMERGENCY!!!

    You do not mention your database, but you should take a look at the INNER JOIN as that'll do what you need from the look of it.

Tags for this Thread

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured