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)

解决方案 »

  1.   

    小弟拙见,不知道这样行不行
    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
      

  2.   

    不好意思写错了:select a.boardid,b.topicid,a.BoardName,b.Title,b.Content
         from table1 a,(select max(topicid) topicid
                          from table2 where a.boardid = table2.boradid) b
      

  3.   

    楼上的不行,一楼正确
    也可以: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
      

  4.   

    我也弄了一个,请指教
    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)
      

  5.   

    create view ppViewASselect b.boardID,b.TopicID,b.title,a.BoardName,b.Contentfrom (select * from TblTopic a where TopicID=
    (select max(topID) from TblTopic where BoardID=A.BoardID))bleft join TblBoard a on b.BoardId=a.BoardId