我有兩個表,想進行連接并提取目標輸出。但我沒有得到如圖所示的預期結果。

我的查詢:
select
a.catalog_number,
a.catalog_image,
b.catalog_description
from
catalog_type a
inner join
catalog_details b on a.catalog_number = b.catalog_number
評論:我應該得到 3 行,但查詢根據連接條件回傳 6 行。
謝謝拉克什
uj5u.com熱心網友回復:
alter table Catalog_Type add Catalog_Type_ID int identity(1,1)
alter table Catalog_description add Catalog_Description_ID int identity(1,1)
select ct.catalag_number, ct.catalog_image,cd.catalog_description
from Catalog_Type as ct
inner join Catalog_description cd
on cd.Catalog_Description_ID = ct.Catalog_Type_ID

因此,您的問題出在模型中,或者出在您對模型和資料的概念中,而不是出在查詢中。
要獲得類似于您在影像上顯示的結果的內容,您需要這樣的內容。

轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/402652.html
標籤:
