-1

My requirement is, there are two tables one is Stock table another one is packaging table. The normalization is 1:M that means 1 stock id can pack into many packages. In the packaging table there are two stockIDs one is FromStockID and another one is StockID. From both stock ids I wanted to retrieve appropriate stockID wise item code.

The data structure is:

enter image description here

I have tried using inner join and got an error.

enter image description here

2
  • 2
    What have you tried? You're on the right track with INNER JOIN. I think I speak for most of us when i say that we want you to learn something, not just give you the code. Commented May 26, 2015 at 20:36
  • 2
    Please post the table definitions and sample data in a consumable way. You're just a few clicks away from a good question. Read here how to create it spaghettidba.com/2015/04/24/… Commented May 26, 2015 at 20:43

1 Answer 1

-1

This query is my solution:

SELECT Packaging_TBL.PackagingID, Packaging_TBL.PackagingDate, Packaging_TBL.FromStockID, (SELECT ItemCode FROM Stock_TBL WHERE StockID = Packaging_TBL.FromStockID) AS FromItemCode, Store_TBL.StoreID, Store_TBL.StoreName, Packaging_TBL.FromCurrentQuantityQuantity, Packaging_TBL.FromCurrentBalanceQuantity, Stock_TBL.StockID, Stock_TBL.ItemCode, Packaging_TBL.Quantity
FROM Packaging_TBL INNER JOIN Stock_TBL ON Packaging_TBL.StockID = Stock_TBL.StockID INNER JOIN Store_TBL ON Packaging_TBL.StoreID = Store_TBL.StoreID
WHERE Packaging_TBL.IsTableStatus = 1
ORDER BY Packaging_TBL.PackagingID ASC

enter image description here

Which is working fine.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.