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:
PHP Code:mysql_query("SELECT * FROM product WHERE id = 2 AND id = 5");
Printable View
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:
PHP Code:mysql_query("SELECT * FROM product WHERE id = 2 AND id = 5");
Hi,
Try this code:
Code:mysql_query("SELECT * FROM product WHERE id IN(2, 5) LIMIT 2");
You can also try an "OR".. For example:
Quote:
mysql_query("SELECT * FROM product WHERE id=2 OR id=5");
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