SQL command to display specific records of the "id" field

9

What SQL statement would display the records where the id field was 22, 23, 25 and 27?

    
asked by anonymous 30.08.2014 / 02:21

3 answers

19

It would be something like:

SELECT * FROM tabela WHERE id IN (22,23,25,27);

The IN Operator:

The IN operator allows you to specify multiple values in a WHERE clause.

Syntax:

SELECT column_name(s)
 FROM table_name
 WHERE column_name IN (value1,value2,...);

It also works with strings:

SELECT * FROM Customers
 WHERE City IN ('Paris','London');

Source: w3schools

    
30.08.2014 / 02:28
5

Basically the same as your previous question . But now you use the OR to select more than one, ie 22 OR 23 OR 25 OR 27, any of them will be selected.

SELECT * FROM tabela WHERE id = 22 OR id = 23 OR id = 25 OR id = 27;
    
30.08.2014 / 02:27
0

Better shape! will select fields as desired

SELECT * FROM tabela WHERE id = 22 and id REGEXP '(23|25|27)';
    
17.02.2017 / 16:13