I’m looking for a way to select until a sum is reached.
My "documents" table has "tag_id" and "size" fields.
I want to select all of the documents with tag_id = 26 but I know I can only handle 600 units of size. So, there’s no point in selecting 100 documents and discarding 90 of them when I could have known that the first 10 already added up to > 600 units.
So, the goal is: don’t bring back a ton of data to parse through when I’m going to discard most of it.
…but I’d also really like to avoid introducing working with cursors to this app.
I’m using MySQL.
You need some way to order which records get priority over others when adding up to your max units. Otherwise, how do you know which set of records that totals up to 600 do you keep?
This is just a basic query to get you started, and there are a number of problems still to solve: