select * from question q left join answer a on q.question_id=a.question_id where q.question_title like '%为什么4%' or a.answer_content like '%为什么4%' 
and select top 1 * from answer where Add_date = ( select Max(add_date) from answer)
and 前面的是查询出答案,and后面的筛选出一条时间最大的一条但是用and报错,用什么将2个语句接起来啊?

解决方案 »

  1.   

    select top 1 from (select * from question q left join answer a on q.question_id=a.question_id where q.question_title like '%为什么4%' or a.answer_content like '%为什么4%') as t order by t.add_date desc
      

  2.   

    select top 1 * from (
    select * from question q left join answer a on q.question_id=a.question_id where q.question_title like '%为什么4%' or a.answer_content like '%为什么4%'
    ) as t order by t.add_date desc
      

  3.   

    消息 156,级别 15,状态 1,第 1 行
    关键字 'from' 附近有语法错误。
    消息 156,级别 15,状态 1,第 2 行
    关键字 'as' 附近有语法错误。
      

  4.   

    消息 8156,级别 16,状态 1,第 1 行
    多次为 't' 指定了列 'question_id'。
      

  5.   

    消息 205,级别 16,状态 1,第 1 行
    使用 UNION、INTERSECT 或 EXCEPT 运算符合并的所有查询必须在其目标列表中有相同数目的表达式。
      

  6.   


       select top 1 * 
         from question q 
    left join answer a 
           on q.question_id = a.question_id 
        where q.question_title like '%为什么4%' 
           or a.answer_content like '%为什么4%' 
          and a.Add_date = ( select Max(add_date) from answer)
      

  7.   

     select top 1 * 
         from question q 
    left join answer a 
           on q.question_id = a.question_id 
        where q.question_title like '%为什么4%' 
           or a.answer_content like '%为什么4%' 
          and a.Add_date = ( select Max(add_date) from answer)
      

  8.   

    select top 1 * from (
    select q.*,a.add_date,a.列名(不要a.question_id) from question q left join answer a on q.question_id=a.question_id where q.question_title like '%为什么4%' or a.answer_content like '%为什么4%'
    ) as t order by t.add_date desc
      

  9.   

    消息 8156,级别 16,状态 1,第 1 行
    多次为 't' 指定了列 'add_date'。
      

  10.   


    select * from question a where a.question_title like '%为什么4%' or 
    (select count(*) from answer b join question a
     on a.question_id = b.question_id 
     where b.answer_content like '%为什么4%')
    我现在换成这样的 它报
    消息 4145,级别 15,状态 1,第 4 行
    在应使用条件的上下文(在 ')' 附近)中指定了非布尔类型的表达式。
      

  11.   


    select top 1 * from question q left join answer a on q.question_id=a.question_id where q.question_title like '%为什么4%' or a.answer_content like '%为什么4%' and a.add_date is not null order by a.add_date desc
      

  12.   


    select * from question q left join answer a on q.question_id=a.question_id 
    where q.question_title like '%为什么4%' or a.answer_content like '%为什么4%' 
    and exists(select top 1 * from answer where Add_date = ( select Max(add_date) from answer))
      

  13.   


    select * from question q left join
    ( select top 1 * from answer where Add_date = ( select Max(add_date) from answer)) a 
    on q.question_id=a.question_id 
    where q.question_title like '%为什么4%' or a.answer_content like '%为什么4%' 
    下面这个简直是瞎写的
      

  14.   


    ---------------//那就去掉and a.add_date is not null 
    //我还以为没有回答的不要呢
      

  15.   

    还是一样的问题啦!解决了只查询出一个答案的问题,因为你再最前面用了top 1 所以只能出一个问题,而且还是查询出的问题是时间最大的一个而难题
      

  16.   

    top 1 去掉了 就可以显示多个答案哦!