看到where語句中有條件:where 1=1 和 1=2或1<>1
用途:
1=1:是為了添加條件時使用and並列其他條件時使用的(動態連接后續條件)
比如:
String sql = "select * from emp where 1=1 ";
if(username!=null)
sql+="and username="+username;
if(password!=null)
sql+="and password="+password;
1=2或1<>1是為了獲取表的結構而拋棄數據,這樣創建的表和原表的字段相同,其他並不能保證相同(例如可為空等和原表均有出入)。
比如: create table emp_tmp as select * from emp where 1=2;
此時再將數據導入: insert into emp_tmp select * from emp;