有人请告诉我SQL查询以获得结果....SQL Server 2008查询从两个表中获取混合数据
谢谢!
从以上两个表,我想要得到的Photo
,Name
,Id of max(id)
从Table-A
每个category_id
对于这Table-B
的parent_id
是1
即
1005 E Byte Apple 3
1002 B Byte Banana 5
1007 G Byte Orange 6
1011 K Byte Mango 7
有人请告诉我SQL查询以获得结果....SQL Server 2008查询从两个表中获取混合数据
谢谢!
从以上两个表,我想要得到的Photo
,Name
,Id of max(id)
从Table-A
每个category_id
对于这Table-B
的parent_id
是1
即
1005 E Byte Apple 3
1002 B Byte Banana 5
1007 G Byte Orange 6
1011 K Byte Mango 7
尝试下面;
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)
它的工作原理!非常感谢。 – Shan
不客气 –
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
它不工作。 – Shan
严重吗?,没有解释你的表是什么,你想要什么结果,什么都没有? – Lamak
@Lamak我编辑了我的问题。 – Shan