作业帮 > 综合 > 作业

sql语句and 1=1是什么意思?

来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/06/05 03:02:20
sql语句and 1=1是什么意思?
select a.ename, a.mgr, a.sal, b.deptno
from emp a, dept b
where a.deptno = b.deptno
and b.deptno in ('ACCOUNTING', 'RESEARCH', 'SALES', 'OPERATIONS')
AND 1=1;
sql语句and 1=1是什么意思?
就是判断一下真假

因为1永远=1,所以肯定为真

不过这里用不用1=1没什么作用,前边就能确定结果了

你可以换成1=0,这样就恒为假,所以当后边是1=0时你选不出来任何数据
再问: 前面确定结果?where t1.id=t2.id and 1=1 and where t1.name=t2.name //那这个情况t1.id=t2.id不成立,后面,t1.name=t2.name就不执行聊吗?大哥
再答: 都执行啊,跟每个条件的顺序无关 那几个and条件都是并列的,只要有一个没对应上,就都查不出来,所以 where t1.id=t2.id and 1=1 and where t1.name=t2.name where t1.id=t2.id and where t1.name=t2.name where t1.id=t2.id and where t1.name=t2.name and 1=1 都是一样的结果,如果你有数据的话,可以测试一下,这三种运行方式
再问: 第一个效率高吧?
再答: 这个不太好说什么效率 因为效率跟表结构,索引等等都有很大关系 你这几个运行的话,估计你数据量也不大,不要单纯看执行查出结果的时间,那个不准,有些东西要分析sql语句的 不过一般的时候在查询里都不太用1=1这样的东西
再问: http://zhidao.baidu.com/question/590860832.html?quesup2&oldq=1 //大哥帮我看看这个问题拜想不通。非常感谢阿
再答: 那个给你答了,要看下你数据库,用法不同,你那个问题在那边追问吧