Sir, I need your help to give me a sql query:
Firstly take a look to the table I have:
1)tbl_Product
-----------------
productId
productName
rate
quantity
Amount
2) tbl_Batch
--------------
batchId
productId
Barcode
Please give me a query to have a output like below:
productId barcode productName Quantity Rate Amount
SQL Suery to join Two table
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Hemant SrivastavaRank #581 · 4.2K reputationPosted Oct 28, 2013, 5:22 AM EDT
SELECT PROD.productId, BACH.barcode, PROD.productName, PROD.Quantity, PROD.Rate, PROD.Amount
FROM tbl_Product AS PROD, tbl_Batch AS BACH
WHERE PROD.productId = BACH.productId
With SQL Join:
SELECT PROD.productId, BACH.barcode, PROD.productName, PROD.Quantity, PROD.Rate, PROD.Amount
FROM tbl_Product AS PROD
INNER JOIN tbl_Batch AS BACH ON PROD.productId = BACH.productId
If tbl_Batch table has null entries corresponding to a productId:
SELECT PROD.productId, BACH.barcode, PROD.productName, PROD.Quantity, PROD.Rate, PROD.Amount
FROM tbl_Product AS PROD
LEFT OUTER JOIN tbl_Batch AS BACH ON PROD.productId = BACH.productId
Raju KatareRank #1,971 · 742 reputationPosted Oct 28, 2013, 2:57 AM EDT
tbl_Product a INNER JOIN tbl_Batch b ON a.ProductId = b.ProductId
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Oct 28, 2013, 2:57 AM EDT
Select p.productId,p.productName,b.Barcode,p.Quantity,p.rate,p.amount
from tbl_Product p inner join
tbl_Batch b on p.productId=b.productId