select
a.BoardId,b.TopicId,a.BoardName,b.Title,b.Content
from TblBoard a,TblTopic b
where a.BoardId=b.BoardId
and b.TopicId=(select max(TopicId) from TblTopic where BoardId=a.BoardId)
a.BoardId,b.TopicId,a.BoardName,b.Title,b.Content
from TblBoard a,TblTopic b
where a.BoardId=b.BoardId
and b.TopicId=(select max(TopicId) from TblTopic where BoardId=a.BoardId)
select a.boardid,b.topicid,a.BoardName,b.Title,b.Content
from table1 a,(select max(title) title
from table2 where a.boardid = table2.boradid) b
from table1 a,(select max(topicid) topicid
from table2 where a.boardid = table2.boradid) b
也可以:select
a.BoardId,b.TopicId,a.BoardName,b.Title,b.Content
from TblBoard a,TblTopic b,(select BoardId,max(TopicId) as TopicId from TblTopic group by BoardId)c
where a.BoardId=b.BoardId
and a.BoardId=c.BoardId
and b.TopicId=c.TopicId
CREATE VIEW ViewLasTopic AS
SELECT TblBoard.BoardId,TblTopic.TopicId,TblBoard.BoardName,
TblTopic.Title,TblTopic.Content
FROM from TblBoard,TblTopic
WHERE TblBoard.BoardId=TblTopic.BoardId and TblTopic.TopicId=(select max(TopicId) from TblTopic where BoardId=TblBoard.BoardId)
(select max(topID) from TblTopic where BoardID=A.BoardID))bleft join TblBoard a on b.BoardId=a.BoardId