有3个表,一个是类别表,一个是新闻表类别表结构如下:newsClass
classid(自动编号) name(类别名称) pre(此类别下的子类id,是varchar类型)
这个pre的内容如: 1,2,3,4新闻表结构如下:news
id title classid
我想实现这样的功能:select title from news where classid in (select pre from newsClass)这样为什么会出错,如果我的sql本身有问题,那么这个sql应该怎么写?谢谢

解决方案 »

  1.   

    或者
    select title from news where classid in (select cast(pre as int) from newsClass)
      

  2.   

    giftzheng() 
    或者
    select title from news where classid in (select cast(pre as int) from newsClass)
    ------------------------------------------------------------------------------------------------
    '1,2,3,4'能转为整型吗?用
    where charindex(','+cast(news.classid as varchar(10))+',',','+newsclass.pre+',')>0
      

  3.   

    select title from news where classid in (select cast(pre as int) from newsClass)
      

  4.   

    select title from news where exists (select 1 from newclass  where pre=(cast(news.classid as varchar(10))))
      

  5.   

    用LIKE 就可以了
    select a.title 
    from news a ,newsClass b 
    where ','+classid+',' like ','+b.pre +','