the 1=1 where condition is always true because always 1 is equal 1 , so this statement will be always true.
While it means nothing sometimes. but other times developers uses this when the where condition is generated dynamically.
for example lets see this code
<?php
//not that this is just example
//do not use it like that in real environment because it security issue.
$cond = $_REQUEST['cond'];
if ($cond == "age"){
$wherecond = " age > 18";
}
$query = "select * from some_table where $wherecond";
?>
so in the above example if the $_REQUEST['cond'] is not "age" the query will return mysql error because there are nothing after the where condition.
the query will be select * from some_table where and that is error
to fix this issue (at least in this insecure example) we use
<?php
//not that this is just example
//do not use it like that in real environment because it security issue.
$cond = $_REQUEST['cond'];
if ($cond == "age"){
$wherecond = " age > 18";
} else {
$wherecond = " 1=1";
}
$query = "select * from some_table where $wherecond";
?>
so now if the $_REQUEST['cond'] is not age the $wherecond will be 1=1 so the query will not have mysql error return.
the query will be select * from some_table where 1=1 and that avoid the mysql error
hope you understand when we use 1=1 while note that the above example is not real world example and it just to show you the idea.
WHERE 1 and ...
would work as well... – Iyartrue
– Prepotent