Where increasing condition

Asked

Viewed 55 times

1

I have a table called users and want to catch some users as per id so I’m doing so:

select * from usuarios where id=2;

Only that I would like to get multiple users with different ids, for example get users who have id 2,8,10,11,20 at once. How could I do that in SQL? If I put the > where id=2 and id=3, wouldn’t work because he makes a comparison. Then someone would tell me how to do?

  • select * from usuarios where id=2 OR id=3 OR id=4...

  • can use with in ex: select * from usuarios where id in (2, 8, 10) or if you prefer, you can use the command or however, it must involve all conditions between parentheses. ex: select * from usuarios where (id=2 or id=3 or id=4). because in this way more conditions can still be placed "outside" of the parentheses. Ex: select * from usuarios where (id=2 or id=3) and usuarios.nome is not null.

1 answer

5

Use the command in, it will check if there are occurrences in the fields, and return the record where there have been occurrences, the purpose of it is to replace several clauses, where the command is used or.

Example:

select * from usuarios where id in(2,8,10,11,20);

See more about him: http://www.tutorialspoint.com/mysql/mysql-in-clause.htm

  • 1

    Dener Bulk !! Know if there is similar to in no sql server ?

  • 2

    @Johndiego Uses in the same way, see the documentation.

  • Too much dough!! Fight

Browser other questions tagged

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