where 1=1跟where 1=0的用法

2014-11-24 10:23:38 · 作者: · 浏览: 0
where 1=1跟where 1=0的用法
当有多条件查询的时候用 where 1=1
如下:
www.2cto.com
Sql代码
select * from emp where 1=1
and empno=7000
and ename=monster;
这种情况是为了房子两个条件都没被选中,即:
Java代码
select * from emp where
的情况出现。添加1=1就不用考虑后面是否有条件语句,是否使用where的情况了。
where 1=0这个情况适用于快速建表
即,你想创建一个表,跟现有表的表结构相同。
www.2cto.com
可这样写:
Java代码
create table nice as (select * from emp where 1=0);
相当于复制了一个表,却没有将数据复制过去,只有表结构。