默认情况下:where 条件语句1;
当有其他查询条件时,要让条件语句1失效,目前是这样写的:where 其他条件 or 1=0 and 条件语句1。
请问还有其他写法吗?上面这样写查起来很慢耶

解决方案 »

  1.   

    where 其他条件 or 1=0 and 条件语句1。你的意思不就是這個嗎,為什麼還整了個1=0?
    不是太明白唉
    where (其他条件) or (条件语句1)
      

  2.   

    看了一下解释计划,上面语句慢的原因是:
    select * from tableA where id in (select aid from tableB where name in ('123')) or 1=0会执行全表扫描,但select * from tableA where id in (select aid from tableB where name in ('123'))这句就不会进行全表扫描,怎么办啊
      

  3.   


    select ta.*
    from tableA ta,tableB tb
    where ta.id=tb.aid and tb.name='123';
      

  4.   


    --或这样写
    select * from tableA 
    where exists (select 1 from tableB where tableB.aid=tableA.id and tableB.name='123');
      

  5.   

    1=0又不是索引列当然会全表扫描了,搞不懂你为什么非要加个1=0,你写个tableA.id=-1(即一个不可能的数不就可以了)
      

  6.   

    全表扫描是or和in的原因和1=0没什么大的关系。改成union all 试试
      

  7.   

    不要用or 或者in 这样会进行全部扫描