select * from news as n where typeid in (select top 4 typeid from news where typeid=n.typeid) 
and 
n.newstype in (select newstype from type)

解决方案 »

  1.   

    select * from news a where newsid in(select top 4 newsid from news where typeid=a.typeid)
      

  2.   

    都不行阿!!!  news表中的typeid是分类的编号  type表中的typeid是分类编号
      

  3.   

    SQL查询语言是一种数据操作语言,对数据库而言,记录本身并没有第一条和第二条之分,所以要用SQL语句直接写出这样的查询(如最新的四条)是不可能的),除非查询日期大于某天或小于某天的记录.另外有的开发工具附带sql查询器具有过滤功能(如PB),可筛选头几条记录或最后几条记录等.
    建议用SQL写个函数完成这个工作.
      

  4.   

    select * from news as n where 新闻标题 in (select top 4 新闻标题 from news where typeid=n.typeid) 
      

  5.   

    其实就是查询news表中相同typeid的4条数据!
      

  6.   

    这个应该是正确的:select * from news as n where 新闻标题 in (select top 4 新闻标题 from news where typeid=n.typeid)
      

  7.   

    select * from news as n where 新闻标题 in 
    (select top 4 新闻标题 from news where typeid=n.typeid)主要是这个字查询,判断一行的纪录的typeid,选出这个typeid的前四个新闻,然后看主查询中的新闻标题是否在这4个新闻中。