PDA

View Full Version : In MySQL, what is the fastest query to retrieve a subset of a table?


yaaay
10-09-2007, 05:00 AM
I have the id's (primary key) of some 300 rows of a given table. I would like to construct the fastest query that simply selects from that table the rows corresponding to those id's.

I was thinking "SELECT * FROM table WHERE id='25' OR id='120000' OR id='65' OR ..." but I'm pretty sure that's not the best solution. I know almost any idea will be pretty fast being id the primary key, but I'm looking for the best you can think of. Thanks for your answers!

gecko_au2003
10-09-2007, 05:02 AM
Using Limit and Order by

http://www.webdevelopersnotes.com/tutorials/sql/online_mysql_lesson_limiting_data_retrieval.php3

That or you can have a drop down box where by you

select * From table where id = dropdown box selection

btw the above is not the exact code but you get the point that way you can allow the end user to select what id or you can make it something else like the last persons name.

Depends on what data you are trying to extract and how you are trying to sort it etc ?