Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Subselect Query Statement

Author  Topic 

sqlnewcomer
Starting Member

2 Posts

Posted - 2011-03-08 : 03:38:18
I have Multiple tables, tbl_employee w/ empid, fname, lname;
tbl_customer w/ custid, fname, lname;
tbl_order w/ orderid, custid, empid, order_date;
tbl_lineitem w/ orderid, prodid, quantity;
tbl_product w/ prodid, descript, list_price;

I want to Query information with order by Order_date,
orderid,
customer's fname & lname,
employee's fname & lname,
descript,
list_price,
quantity,

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2011-03-08 : 03:51:24
Looks like homework.

Hint: Join tbl_customer with Order on custid
Join tbl_product with order on prodid
Join tbl_lineitem with Order on OrderID and with product on Prodid.
Go to Top of Page

sqlnewcomer
Starting Member

2 Posts

Posted - 2011-03-08 : 10:42:50
This is what I have for my query so for
select a.orderid, a.custid, a.empid, a.order_date, a.delivery, a.payment_type,
b.lineitemid, b.orderid, b.prodid, b.quantity, b.sale_price
from [order] a, lineitem b
where a.orderid = b.orderid

But i want the names of emloyees and customers.
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2011-03-08 : 10:53:47
something to start with:

select a.orderid, a.custid, a.empid, a.order_date, a.delivery, a.payment_type,
b.lineitemid, b.prodid, b.quantity, b.sale_price,
c.fname, c.lname
from tbl_customer c inner join [order] a on c.CustId = a.custid
inner join tbl_product tp on tp.prodid = a.prodid
inner join lineitem b on b.orderid = a.orderid and tp.prodid = b.prodid

Note: No testing carried out.

If you get any syntax error try to do it yourself. It will help you in learning.
Go to Top of Page
   

- Advertisement -