SQL查询时通常会使用一下语句:
select * from finance.finance_records l
where l.status= 1 limit 20;
- 如果我们关联表的时候,有时候不能定位到时什么错误,其实,1=1 是永恒成立的,意思无条件的,也就是说在SQL语句中有没有这个1=1都可以。
select * from finance.finance_records l
where 1 = 1
and l.status= 1 limit 20;
where 1 = 1,就是应用程序根据用户选择项的不同拼凑where条件时用的,如果where 1 = 1 后面没有加任何条件也不会出错,想要加查询条件可以直接在 where 1 = 1 and 条件…依次加
如果不用1=1的话,每加一个条件,都要判断前面有没有where 条件,如果没有就写where …,有就写and语句,因此此时用1=1可以简化了应用程序的复杂度