0

Is there a way to query data to display multiple rows with multiple selector?

like:

SELECT * FROM `book` WHERE `book`.id = 1 AND `book`.id = 2;

table:

id name
1  book1
2  book2
3  book3
4  book4

I dun suppose looping for each id is favourable.

1
  • Assuming you are using backticks to escape identifiers, I am tagging this question with mysql RDBMS tag. Commented Jun 27, 2015 at 22:35

2 Answers 2

3

Well, yeah, you can use in, but this is the same as multiple or, not and – one value can't be equal to the two unequal values at once:

select *
from `book`
where `book`.id in(1, 2)
Sign up to request clarification or add additional context in comments.

Comments

2

One solution you have, but you made an error. An id cannot be both 1 and 2, so you need to use OR to return those rows that are either 1 or 2.

SELECT * FROM `book` WHERE `book`.id = 1 OR `book`.id = 2;

A slightly simpler notation would be:

SELECT * FROM `book` WHERE `book`.id in (1, 2);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.