ID         URL           TITLE            BODY
1    WWW.BAIDU.COM      *******         ********
2    WWW.SINA.COM.CN    *******         ********
3    WWW.SOHU.COM       *******         ********
   
要求:比如查询“BAIDU”,在URL中有就先返回,在TITLE中有就第二个返回,在BODY中有就第三返回。类似搜索引擎!都没有就不返回。

解决方案 »

  1.   

    不考虑效率select * from where url like '%BAIDU%'
    union
    .... where title like ...
    union 
    .... where body like ...
      

  2.   

    分成三个查询,把结果联合在一起
    select ..... union select ...... union select .......
      

  3.   

    select id,c from
    (
    select id,url as c from table
    union
    select id,title as c from table
    union
    select id,body as c from table 
    ) exp1
    where c like='baidu' order by id
      

  4.   

    错了,应该是c like '%baidu%'