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");
| SitePoint Sponsor |
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");
Free: Web Programming Courses HTML, CSS, Flash
Web Programming: AJAX Course and PHP-MySQL Course video Lessons
Good JavaScript and jQuery course for beginners
You can also try an "OR".. For example:
mysql_query("SELECT * FROM product WHERE id=2 OR id=5");
___________________________________________________________________
ProntoScreen.com - Criminal Background Check
ContactLensBrands.com - Compare Contact Lenses
CriminalBase.com - Instant Background Check
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
Community Team Advisor
Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator
Bookmarks