Select ID,Title,Type,KeyWords,TextSource,CreateDate,Content From TC_News Where KeyWords = Select KeyWords From TC_News Where ID=2这是我写的一个SQL语句,但定个SQL语句语法一定是错误的,请高手帮忙解决.
我要实现的功能就是在网站页面上根据关键字(字段是KeyWords)显示某篇文章(比如:ID=2的文章)的相关文章标题(字段是Title).
请高手帮忙解决!谢谢!

解决方案 »

  1.   

    Select ID,Title,Type,KeyWords,TextSource,CreateDate,Content From TC_News Where KeyWords = (Select KeyWords From TC_News Where ID=2) T
      

  2.   

    Select ID,Title,Type,KeyWords,TextSource,CreateDate,Content From TC_News Where KeyWords in (Select KeyWords From TC_News Where ID=2)
      

  3.   

    新问题出现----还是关于这个SQL语句的问题,请高手指点说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误信息: CS1026: 应输入 )源错误: 行 33:         //SqlCommand cmdRelating = new SqlCommand("Select ID,Title,Type,KeyWords,TextSource,CreateDate,Content From TC_News Where KeyWords in (Select KeyWords From TC_News Where ID=idParas", conn);
    行 34:         conn.Open();
    行 35:         SqlDataAdapter sda = new SqlDataAdapter("Select ID,Title,Type,KeyWords,TextSource,CreateDate,Content From TC_News Where KeyWords in (Select KeyWords From TC_News Where ID=Request.Params["ID"];", conn);
    行 36:         DataSet ds = new DataSet();
    行 37:         sda.Fill(ds);
     源文件: e:\n\3CMarket\newsArticle.aspx.cs    行: 35 
      

  4.   

    我想问题应试出在ID=Request.Params["ID"]
    这个地方,但就不知怎么解决好.
    请指教
      

  5.   

    SqlDataAdapter sda = new SqlDataAdapter("Select ID,Title,Type,KeyWords,TextSource,CreateDate,Content From TC_News Where KeyWords in (Select KeyWords From TC_News Where ID="+int.parse(Request.Params["ID"])+")", conn);
      

  6.   

    SqlDataAdapter sda = new SqlDataAdapter( string.Format("Select 
      ID,Title,Type,KeyWords,TextSource,CreateDate,Content From TC_News Where ID<>{}
      and KeyWords in (Select KeyWords From TC_News Where ID={0})",
      Request.Params["ID"]), conn);sql server编译时会将“in”翻译为inner join然后才开始进行优化。如果你懂T-SQL,最好直接写inner join的代码更容易人工看出优化的可能性。
      

  7.   

    Where ID<>{}  -->  Where ID<>{0}