Select different value from "X" name

Asked

Viewed 83 times

3

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

I created 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 column REGIAO, I want you to return only customers who are NOT from paul.

Can you please help me?

  • Thank you so much for helping Leandro. It worked.

  • If an answer solved your problem, mark it as the solution.

3 answers

4

It is possible using the operator !=

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 <>:

  1. Mysql 5.1
  2. Postgresql 8.3
  3. Sqlite
  4. Oracle 10g
  5. Microsoft SQL Server 2000/2005/2008/2012/2016
  6. IBM Informix Dynamic Server 10
  7. Interbase / Firebird
  8. Apache Derby 10.6
  9. Sybase Adaptive Server Enterprise 11.0
  • 1

    Remember that whenever possible, normalize the database and use domain tables, where the query fields are foreign key in the main table. This way the searches will be more efficient, avoiding text search.

  • Thanks for the help Luiz.

2

The ideal is that you work with the 'sao paulo' region id and not with a text code. But just use the operator <>

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

0


I do not know what version of the comic used, because the question is without the flag. In Postgres, you can use the NOT ILIKE:

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

Seeing at SELECT I put, there’s the ILIKE also (where the LIKE, the difference being mandatory in LIKE to be written as it should be recorded: capital or minuscule).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.