greedyman — 2013-01-13T10:56:52-05:00 — #1
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");
marplo — 2013-01-13T11:14:04-05:00 — #2
Try this code:
mysql_query("SELECT * FROM product WHERE id IN(2, 5) LIMIT 2");
greedyman — 2013-01-13T12:14:23-05:00 — #3
imsas — 2013-01-14T22:17:04-05:00 — #4
You can also try an "OR".. For example:
mysql_query("SELECT * FROM product WHERE id=2 OR id=5");
greedyman — 2013-01-14T23:21:55-05:00 — #5
Thanks but I want to display all them.
spacephoenix — 2013-01-15T02:30:10-05:00 — #6
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
greedyman — 2013-01-15T03:57:35-05:00 — #7
Oh! I see. It's very useful. Thank you and sorry imsas!