Dear All,
I am beginners in MS Sql, now I have three tables (Companies, Product, SaleBody). and their fields are
(CompanyId, CompanyName), (ProductId, ProductName, CompanyId, PurchaseSTPrice, TradePrice), (SerialNo, SaleId, ProductId, Quantity, Price, TotalPrice)..............
I want to create Report in which I want (companies.CompanyName, product.ProductName, product.TradePrice, salbody.TotalPrice)

     How can I get these fields from 3 tables. 

     I am very thankful to you all..... 

     and wait for your reply
SELECT c.CompanyName, p.ProductName, p.TradePrice, s.TotalPrice
FROM Companies c, Product p, SaleBody s
WHERE c.CompanyId = p.CompanyId
AND p.ProductId = s.ProductId

You simply need to use joins between the three tables. Here is an example:

SELECT Companies.CompanyName, Product.ProductName, Product.TradePrice, SaleBody.TotalPrice
Product ON SaleBody.ProductId = Product.ProductId INNER JOIN
Companies ON Product.CompanyId = Companies.companyId

sample video tutorial on SQL Inner Join:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.