Jump to content

After query, would like selected items to be flagged and not reused


kenwx23

Recommended Posts

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.