我想在mysql中实现这样一个功能
select a.name from tableA as a,tableB as b where a.name like b.name and b.title like '%String%'
关键是这句 a.name like b.name 这样写的话like的结果就是 = 而不是like 请问各位大侠在mysql中能不能这样写select语句。

解决方案 »

  1.   

    这个倒真没注意过,不过可以试试
    where a.name like '%b.name%' 
      

  2.   

    可以这样写的。你的语句相当于select a.name from tableA as a,tableB as b where a.name = b.name and b.title like  '%String% ' 
    MYSQL中如果两字字段LIKE的话就相当于=操作。
      

  3.   

    不过建议你不要这样写。因为 where a.name like b.name 用不到索引,而 where a.name = b.name 就可以用到索引 。
      

  4.   

    嗯,确实是的,我得出的结果就是 a.name = b.name
    a.name like '%b.name%' 和 a.name liek '%'.b.name.'%'都试过了,没有用。
    看样子还是写程序实现吧。多谢楼上两位
      

  5.   

    不是的,我现在写的是个例子,具体的目的是这样的。
    我现在有三个表
    tags_tree,scene和movies
    tags_tree表结构:
    id 
    tagNode
    tagName
    ...scene表结构:
    id
    tags
    programID
    ....movies表结构:
    id
    name
    ....
    我现在要做的是要在tags_tree中like一下
    语句应该这样写
    select s.* from tags_tree as t,scene as s,movies as m where s.tags like t.tagNode and s.programID = m.id and t.tagNode like '%String%'
    具体要实现的就是这个意思 就是说要在tags_tree中like一个结果,然后在把结果在scene中like关键就是在scene中like这一步。
      

  6.   

    唉,不想在这上面花功夫了,我在程序端实现了,不过我还是想知道在sql语句中如何实现,希望上帝老兄给于指点。