Results 1 to 3 of 3

Thread: Query multiple tables

  1. #1
    Senior Member
    Join Date
    Feb 2012
    Location
    Rome - Italy
    Posts
    1,884

    Query multiple tables

    Hi,
    Im trying to wryte a one to many query:

    I've follow this sample
    https://www.lianja.com/community/sho...highlight=join

    Code:
    select orders.orderid, orders.shipvia, shippers.companyname, order_details.productid from orders left outer join order_details on orders.orderid = order_details.orderid inner join shippers on orders.shipvia = shippers.shipperid
    I expect multiple records for the same order.. but I get only the first row for each order.

    only this work, but I need a third table on the join
    Code:
    select orders.orderid, orders.shipvia, order_details.productid from orders left outer join order_details on orders.orderid = order_details.orderid
    whats wrong?

    thanks
    Fabio

  2. #2
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,106
    Is this better:
    Code:
    select orders.orderid, orders.shipvia, order_details.productid, shippers.companyname from order_details join orders on order_details.orderid=orders.orderid join shippers on orders.shipvia = shippers.shipperid
    ORDERID SHIPVIA PRODUCTID COMPANYNAME

    10248 3 39 Federal Shipping
    10248 3 59 Federal Shipping
    10248 3 1 Federal Shipping
    10249 1 49 Speedy Express
    10249 1 48 Speedy Express
    10250 2 24 United Package
    10250 2 10 United Package
    10250 2 70 United Package
    10251 1 31 Speedy Express
    10251 1 5 Speedy Express
    10251 1 6 Speedy Express


  3. #3
    Senior Member
    Join Date
    Feb 2012
    Location
    Rome - Italy
    Posts
    1,884
    Ok, but if I've a order without a detail? This query work?
    Tomorrow I try.
    Tank fabio

Bookmarks

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
  •  
Journey into the Cloud
Join us