Select value other than "X" name

3

How do I select only the different ratings of "X" in a given column?

I created the select below:

SELECT top 1000*
  FROM [tabela_clientes] WITH (NOLOCK)
  WHERE STATUS= 'pendente' and status_2= 'pagamento'
  and REGIAO= 'sao paulo' -----------> aqui seria apenas diferente de sao paulo.

In the REGIAO column, I want to return only those clients that are NOT from Sao Paulo.

Can you help me please?

    
asked by anonymous 04.06.2018 / 22:28

3 answers

0

I do not know which version of DB is used, since the question is without the flag. In Postgres , you can use NOT ILIKE :

SELECT *
FROM   tabela_clientes
WHERE  status ILIKE 'pendente'
AND    status_2 ILIKE 'pagamento'
AND    regiao NOT ILIKE 'sao paulo'

Seeing in the SELECT that I put, there is the ILIKE also (where you can also use the LIKE , the difference being the obligatoriness in LIKE to be written as it should be written: uppercase or lowercase ).

    
04.06.2018 / 22:51
4

It is possible using the !=

SELECT top 1000 *
  FROM [tabela_clientes] WITH (NOLOCK)
  WHERE STATUS = 'pendente' and status_2 = 'pagamento'
  and REGIAO != 'sao paulo'

or <>

SELECT top 1000 *
      FROM [tabela_clientes] WITH (NOLOCK)
      WHERE STATUS = 'pendente' and status_2 = 'pagamento'
      and REGIAO <> 'sao paulo'

Main databases that support both != and <> :

  • MySQL 5.1
  • PostgreSQL 8.3
  • SQLite
  • Oracle 10g
  • Microsoft SQL Server 2000/2005/2008/2012/2016
  • IBM Informix Dynamic Server 10
  • InterBase / Firebird
  • Apache Derby 10.6
  • Sybase Adaptive Server Enterprise 11.0
  • 04.06.2018 / 22:56
    2

    Ideally, you should work with the 'sao paulo' region id rather than a text code. But you only have to use the <>

    SELECT top 1000 *
      FROM [tabela_clientes] WITH (NOLOCK)
      WHERE STATUS = 'pendente' and status_2 = 'pagamento'
      and REGIAO <> 'sao paulo'
    
        
    04.06.2018 / 22:37