How to select multi rows from one table with id?

I want to select two rows from a table, I wrote a query but it’s not work. it’s seem wrong. How should I repair?

Here is code:


mysql_query("SELECT * FROM product WHERE id = 2 AND id = 5");

Hi,
Try this code:

mysql_query("SELECT * FROM product WHERE id IN(2, 5) LIMIT 2");

Great! Thanks.

You can also try an “OR”… For example:

mysql_query(“SELECT * FROM product WHERE id=2 OR id=5”);

Thanks but I want to display all them.

IN does the same as a group of ORs, looking around it appears that IN runs faster then a group of ORs. For a small site or one with not too many records the difference in speed probably won’t be worth worrying about but for a big site you’ll want to go with IN. Another advantages of IN is that it’s a little more readable and saves some typing. I personally would go for IN, not so much for the speed of execution but more for saving on typing and it’s more readable.l

Oh! I see. It’s very useful. Thank you and sorry imsas!