select * from table where 1=1中的1=1是什么意思

2025-03-09 09:08:26
推荐回答(2个)
回答1:

就是条件为真的意思,就这条语句来说就等同于select * from table(1=1就是条件为真)

select * from table where 1=1这样写一般是编程时查询语句有判断拼接条件时用的

如 :

str=“select * from table where”;

if(a=1){str=str+" user=abc";}

if(b=1){str=str+" and pass=123";}

当IF条件成立时select * from table where  and user=abc and pass=123

这是条可以执行的语句

担当IF条件不成立时 select * from table where

这是条执行会报错的语句

如果str=“select * from table where 1=1”;

if(a=1){str=str+" and user=abc";}

if(b=1){str=str+" and pass=123";}

这样写的话即使IF条件不成立select * from table where 1=1同样可以正常执行



回答2:

没什么用,就是程序有时候拼凑SQL语句的时候用来放在那里,后面好拼凑一点。