-1

有人请告诉我 SQL 查询以获得结果....

谢谢!

在此处输入图像描述

从上面的两个表中,我想从其中的每个表中获取Photo, Name,即Id of max(id)Table-Acategory_idparent_idTable-B1

1005 E Byte Apple 3
1002 B Byte Banana 5
1007 G Byte Orange 6
1011 K Byte Mango 7
4

2 回答 2

2
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
于 2012-09-04T18:54:05.990 回答
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) 
于 2012-09-04T18:57:22.440 回答