select * from 
(
  Select ID,Title,Content,'tb1' as tablename from tb1
  union all
  Select ID,Title,Content,tb2' from tb2
  union all
  Select ID,Title,Content,'tb3' from tb3
  union all
  Select ID,Title,Content,'tb4' from tb4
) t
where title like "%myname%"

解决方案 »

  1.   

    select * from 
    (
      Select ID,Title,Content,'tb1' as tablename from tb1
      union all
      Select ID,Title,Content,'tb2' from tb2
      union all
      Select ID,Title,Content,'tb3' from tb3
      union all
      Select ID,Title,Content,'tb4' from tb4
    ) t
    where title like "%myname%"漏了个',:)
      

  2.   

    --试试
    select * from 
    (
      Select ID,Title,Content,'tb1' as tb from tb1
      union all
      Select ID,Title,Content,'tb2'  from tb2
      union all
      Select ID,Title,Content,'tb3'  from tb3
      union all
      Select ID,Title,Content,'tb4'  from tb4
    ) t
    where title like "%myname%"
      

  3.   

    对了,括号后面应该加一个as 吧?本人sql学得很水./_\....