簡體   English   中英

SQL Server 2008查詢以從兩個表中獲取混合數據

[英]SQL Server 2008 query to get mixed data from two tables

有人請告訴我SQL查詢以獲取結果。...

謝謝!

在此處輸入圖片說明

從上面的兩個表中,我想從Table-ATable-B parent_id1每個category_id獲取Id of max(id)PhotoNameId of max(id)

1005 E Byte Apple 3
1002 B Byte Banana 5
1007 G Byte Orange 6
1011 K Byte Mango 7
select a.id,a.name,a.photo,b.category_name,b.category_id
from table-A a join table-B s ON a.category_id = b.category_id
where parent_id = 1

請嘗試以下;

Select TBLA.ID, TBLA.Name, TBLA.Photo, TBLB.Category_Name, TBLB.Category_ID
From [table-B] TBLB
Inner Join [table-a] TBLA On TBLA.Category_ID = TBLB.Category_ID
Where TBLB.Parent_ID = 1 
And TBLA.ID = (Select Max(ID) 
      From [table-a]
      Where Category_ID = TBLB.Category_ID) 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM