异常查询ID

时间:2014-05-12 03:50:06

标签: php mysql exception select

除了 id 等于1和2的用户之外,如何进行查询以选择所有用户

SELECT *
FROM $viewUsuarios
WHERE login LIKE '%$busca%'
  OR nome LIKE '%$busca%'
  OR sobrenome LIKE '%$busca%'
  OR senhasErradas LIKE '%$busca%'
  OR ADMIN LIKE '%$busca%'
  OR ativo LIKE '%$busca%'
  OR verificado LIKE '%$busca%'
  OR termoUso LIKE '%$busca%'
  OR versaoTermoUso LIKE '%$busca%'
ORDER BY id ASC LIMIT $contadornInicioRegistros,
                      $limiteRegistros

3 个答案:

答案 0 :(得分:0)

您将添加AND 您的查询应该如下所示。

SELECT * FROM $viewUsuarios 
           WHERE login LIKE '%$busca%' OR 
                 nome LIKE '%$busca%' OR 
                 sobrenome LIKE '%$busca%' OR 
                 senhasErradas LIKE '%$busca%' OR 
                 admin LIKE '%$busca%' OR 
                 ativo LIKE '%$busca%' OR 
                 verificado LIKE '%$busca%' OR 
                 termoUso LIKE '%$busca%' OR 
                 versaoTermoUso LIKE '%$busca%' AND 
                 id>2 
           ORDER BY id ASC 
           LIMIT $contadornInicioRegistros, $limiteRegistros

我希望它可以帮助..;)

答案 1 :(得分:0)

此查询应该有效。

SELECT * FROM users WHERE id NOT IN (1, 2)

答案 2 :(得分:0)

我相信一个简单的!=运算符就足够了。

实施例。 "SELECT * from {$viewUsarios} WHERE id != 1 AND id != 2";

来源:http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html