次のように3つのテーブルがあります。
バーコードグループマップ
カテゴリーマスター
製品マスター:
これらの 3 つのテーブルから、次のクエリを作成しました。
select bgm.BarcodeItem,
cm.CategoryID,cm.CategoryName,pm.ProductName,pm.ProductID,bgm.EffectFrom,bgm.Groups
from BarcodeGroupMap bgm,CategoryMaster cm,ProductMaster pm where
bgm.ProductID=pm.ProductID and bgm.categoryID=cm.CategoryID
このクエリの結果は次のようになります。
クエリ結果のバーコードが繰り返されていることがわかります。
Barcodegroupmapテーブルの最新のCreateddateに従って、1 つのバーコードを一度だけ表示したかっただけです。
このために、次のクエリを作成しました。
select bgm.BarcodeItem,
cm.CategoryID,cm.CategoryName,pm.ProductName,pm.ProductID,bgm.EffectFrom,bgm.Groups
from BarcodeGroupMap bgm,CategoryMaster cm,ProductMaster pm where
bgm.ProductID=pm.ProductID and bgm.categoryID=cm.CategoryID and
bgm.BarcodeItem= select BarcodeItem from BarcodeGroupMap bm1 where
CreatedDate= (select top 1 CreatedDate from BarcodeGroupMap bm2
)order by bm1.BarcodeItem
しかし、正しい結果が得られません。
私を助けてください。
Barcodegroupmap の最新の作成日に従って、1 つのバーコード項目を 1 回だけ表示したいだけです。