What SQL statement would display the records where the id
field was 22, 23, 25 and 27?
What SQL statement would display the records where the id
field was 22, 23, 25 and 27?
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
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;
Better shape! will select fields as desired
SELECT * FROM tabela WHERE id = 22 and id REGEXP '(23|25|27)';