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
FROM SaleBody INNER JOIN
Product ON SaleBody.ProductId = Product.ProductId INNER JOIN
Companies ON Product.CompanyId = Companies.companyId

sample video tutorial on SQL Inner Join: http://youtu.be/ClcqCB4sEEs
summary: http://www.itgeared.com/articles/1166-sql-inner-join/

Be a part of the DaniWeb community

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