Conecting to a 3rd table

  • this is what i have and it works perfect but i need to add data from a 3rd table

    Select

    Orders.OrderDate,

    Orders.OrderId,

    Orders.OrderNotes,

    Orders.Custom_field_vehicleinfo,

    Orders.Salesrep_Customerid,

    OrderDetails.ProductCode,

    OrderDetails.Productname,

    From Orders

    join Orderdetails

    on orders.orderid = orderdetails.orderid

    Where Orders.Orderstatus in ('Pending', 'Processing', 'New')

    Order By Orders.Orderdate ASC

    The third table is called products and all i need is to select the customfield4 and have it print with the rest of these... so it should look like

    Select

    Orders.OrderDate,

    Orders.OrderId,

    Orders.OrderNotes,

    Orders.Custom_field_vehicleinfo,

    Orders.Salesrep_Customerid,

    OrderDetails.ProductCode,

    OrderDetails.Productname,

    Products.CustomFeild4

    From Orders

    join Products

    join Orderdetails

    on orders.orderid = orderdetails.orderid

    Where Orders.Orderstatus in ('Pending', 'Processing', 'New')

    Order By Orders.Orderdate ASC

  • This is actually quite simple, unfortunately I can't help you as you haven't provided the DDL (CREATE TABLE statements) for the tables involved, sample data for the tables to test with, and the expected results based on the sample data you provide.

    Please remember we can't see what you you see unless you provide us with the information we need to be able to help you.

  • Just a wild stab in the dark, but I think you want something like this:

    SELECT

    Orders.OrderDate,

    Orders.OrderId,

    Orders.OrderNotes,

    Orders.Custom_field_vehicleinfo,

    Orders.Salesrep_CustomerId,

    OrderDetails.ProductCode,

    OrderDetails.ProductName,

    Products.CustomField4

    FROM

    Orders

    INNER JOIN

    OrderDetails

    ONOrders.OrderId = OrderDetails.OrderId

    INNER JOIN

    Products

    ONOrderDetails.ProductId = Products.ProductId

    WHERE

    Orders.OrderStatus IN ('Pending', 'Processing', 'New')

    ORDER BY Orders.OrderDate ASC

  • Is there something wrong with all the answers I gave you on the other thread you had on this problem? http://www.sqlservercentral.com/Forums/Topic1050944-391-1.aspx

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply