How to select all id’s except one?

Asked

Viewed 3,761 times

4

Is there any way in SQL I get all the data except an ID?

For example (I know this does not exist in SQL)

Select * From Utilizadores Where id_ut != 1; 
  • 4

    There is the different <> ou !=, has not sometimes accompanied by the in, which bank is using?

  • I wanted to understand why using the != did not solve your problem. You asked a question with the solution already...

2 answers

11


Besides the way you’ve already asked your question, not equal to ( != ), can do in other ways:

Using the other than:

Select * From Utilizadores Where id_ut <> 1;  

Using the not in:

Select * From Utilizadores Where id_ut not in (1); 
/*Usando o not in, você pode passar uma lista de valores (1,2,10)*/

Remembering that you can use these 3 operators ( <>, !=, not in ) not only with numerical values, but with texts as well. For example:

Select * From Utilizadores Where nome_ut not in ('João', 'Pedro', 'Maria'); 

Select * From Utilizadores Where nome_ut <> 'João'; 

Select * From Utilizadores Where nome_ut != 'João'; 

1

Hey, do it like this:

Select * From Utilizadores Where id_ut <> 1; 
  • 5

    Roger, can you explain why this line of code solves the problem? So it helps to understand the problem and the answer to those who don’t know what <> means. Thank you!

Browser other questions tagged

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