What does “WHERE 1” mean in SQL?

后端 未结 3 1182
情话喂你
情话喂你 2021-01-03 21:37

Sometimes phpMyAdmin generates queries like:

SELECT * 
FROM  `items` 
WHERE 1 
LIMIT 0 , 30

I wonder if WHERE 1 has any meanin

3条回答
  •  北海茫月
    2021-01-03 22:24

    WHERE 1 is a synonym for "true" or "everything."

    It's a shortcut so they don't have to remove the where clause from the generated SQL.

    Otherwise, you would write something like this:

    $sql = "SELECT * FROM `errors`";
    if ($hasWhereClause == true) {
      $sql .= " WHERE $whereClause";
    }
    $sql .= "LIMIT 0 , 30";
    

提交回复
热议问题