![](/img/trans.png)
[英]SQL Query (SQL Server 2008) to retrieve data from two tables and group results
[英]SQL Server 2008 query to get mixed data from two tables
有人請告訴我SQL查詢以獲取結果。...
謝謝!
從上面的兩個表中,我想從Table-A
為Table-B
parent_id
為1
每個category_id
獲取Id of max(id)
的Photo
, Name
, Id 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.