Hi, I'm trying to select a distinct field from DB like this select field1 from table where memberID='1' group by field1 Code (markup): The DB has thousands of records. I want the query to read just 100 records "for each memberID" specified in query and then exit. I cannot use "limit 100 " because members might have less than 100 records, in which case the query will scan the whole table. What will be the query here? (scans 100 records of memberID specified and then exists) Thanks
If your table is set up correctly with the right datatypes and indexes it shouldn't matter if it has to query the whole table. Use limit.
I think it'll matter in long run when table grows very large. I cannot delete data from this table, so at some point of time it'll take minutes to go through the entire table. My requirement is to select a certain distinct field of a user when they visit a section of the website. These distinct records will never exceed 100 records in total. So I'm thinking whats the point in reading all 2 million records or so... Is there any way to do this? thanks
Your post was #18904200 in the forum posts table - didn't take too long to come up for me - along with all the other posts in the thread and all the extra info around alerts, etc. Use indexes and you'll be fine.
If you are not too sure about this (sarahk's suggestion regarding indexes, and also in the other post she mentioned about using the right data types), you might be better off posting your table STRUCTURE (not the data, obviously) and we might be able to give some tips on fine tuning it.