Select a.ID, b.Name, a.Place
from StorageItem a
inner join Storage b
on (a.id = b.id)
上記のクエリは、その名前でStorageItemテーブル内のすべてのアイテムを返します。これをフィルタリングして特定のアイテムのアイテムのみを返す場合は、次のようにwhere句を追加します。
Select a.ID, b.Name, a.Place
from StorageItem a
inner join Storage b
on (a.id = b.id)
where a.item_id = 1 -- place the item id here
次のようなパラメータでwhereを使用できます。
MyQuery.Sql.Text := ' Select a.ID, b.Name, a.Place from StorageItem a
+ ' inner join Storage b on (a.id = b.id) '
+ ' where a.item_id = :ItemNo ';
MyQuery.ParamByName('ItemNo').asInteger := 1;
MyQuery.Open;
上記のクエリをdbGridに割り当てます
また、MasterSourceプロパティを使用して、「where」部分を使用せずにリレーションを作成することもできます