Question Creating SQL query

samir_gambler

Member
Joined
Jul 12, 2012
Messages
6
Programming Experience
1-3
Hello,

I am new to sql. Can anyone please help me in creating query. I have three table
1. Stock containing fields -> StockID(primary key), CategoryID, StockName, StockOnHand, UnitPrice, [CashVaue-StockOnHand], Margin, SalePrice
2.OrderDetails containing fields -> OrderID, StockID, Quantity, [Sub-total]
3. Sales containing fields -> OrderID(primary key), CustomerID, EmployeeID, Date, Net, Discount, Total, OfficialReceiptNumber, EVAT
4.Employee containing fields -> EmployeeID(primary key), LastName, FirstName, JobDescription.

for a given orderID I have to extract information from all the four table.
i.e from order id we will get stockid quantity and sub-total from orderdetailtable
from OrderID we will get CustomerID, EmployeeID, Date, Net, Discount, Total, OfficialReceiptNumber, EVAT
From employeeID(which we got from OrderID table) we will get FirstName, LastName
from stockid we will get stockname, SalePrice

Can anyone please help me to write the query to get all these information.

Thanks
 
VB.NET:
SELECT s.StockName, s.SalePrice,o.Quantity,o.StockID, sa.EmployeeID,sa.Date,sa.Net, sa.Discount, sa.Total, sa.OfficialReceiptNumber,sa.EVAT,e.FirstName, e.LastName 
FROM Stock s 
LEFT JOIN OrderDetails o ON o.StockID=s.StockID
LEFT JOIN Sales sa ON sa.OrderID=o.OrderID 
LEFT JOIN Employee e ON e.EmployeeID = sa.EmployeeID
WHERE o.OrderID = 12345
 
VB.NET:
SELECT s.StockName, s.SalePrice,o.Quantity,o.StockID, sa.EmployeeID,sa.Date,sa.Net, sa.Discount, sa.Total, sa.OfficialReceiptNumber,sa.EVAT,e.FirstName, e.LastName 
FROM Stock s 
LEFT JOIN OrderDetails o ON o.StockID=s.StockID
LEFT JOIN Sales sa ON sa.OrderID=o.OrderID 
LEFT JOIN Employee e ON e.EmployeeID = sa.EmployeeID
WHERE o.OrderID = 12345

Thanks:02.47-tranquillity:
 
Back
Top