kenwx23 Posted November 28, 2006 Share Posted November 28, 2006 I'm a MySQL novice, and I don't even know if there is a way to do this.I have a simple table containing just 2 fields and about 15,000 entries...one contains an ID (which is just an incremental number) and the other a phrase. I will be doing queries selecting 50 random entries from the table. Somehow, once those 50 are selected and returned, I would like to flag them so that they cannot be selected again UNTIL I exhaust the entire list. So, I'd like to get 50 random at a time, until all 15,000 are gone, and then start over. If that isn't possible, I suppose I can just select the first 50 every time and delete the first 50 when I am done.Thanks for any assistance in advance!Ken Quote Link to comment https://forums.phpfreaks.com/topic/28679-after-query-would-like-selected-items-to-be-flagged-and-not-reused/ Share on other sites More sharing options...
btherl Posted November 28, 2006 Share Posted November 28, 2006 You can flag them by adding another column to the table for the flag..Or you can make another table storing the ids you've already used. Then when you want to fetch more entries, you can join with the "used" table and only select rows that don't match that table.Basically, there's no way to "flag" something in a database without adding data to be the flag. There's no flagging mechanism.Or, another thing you could do is use a cursor and fetch 50 elements at once. As long as it's all being done in the same process, that ought to work with no problems. But I assume you will be doing these fetches over a period of time, and in seperate processes. Quote Link to comment https://forums.phpfreaks.com/topic/28679-after-query-would-like-selected-items-to-be-flagged-and-not-reused/#findComment-131266 Share on other sites More sharing options...
fenway Posted November 29, 2006 Share Posted November 29, 2006 I would tend to agree.. you should create another table with all the 15K ids in "random" order, and then go through that table ORDER by PK LIMIT 50, joined with your original table. Quote Link to comment https://forums.phpfreaks.com/topic/28679-after-query-would-like-selected-items-to-be-flagged-and-not-reused/#findComment-132078 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.