Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8554889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:59:20+00:00 2026-06-11T14:59:20+00:00

I am looking at this problem from a TSQL point of view, however any

  • 0

I am looking at this problem from a TSQL point of view, however any advice would be appreciated.

Scenario

I have 2 sets of criteria which identify items in a warehouse to be selected.

Query 1 returns 100 items
Query 2 returns 100 items

I need to pick any 25 of the 100 items returned in query 1.
I need to pick any 25 of the 100 items returned in query 2.
– The items in query 1/2 will not be the same, ever.

Each item is stored in a segment of the warehouse.

A segment of the warehouse may contain numerous items.

I wish to select the 50 items (25 from each query) in a way as to reduce the number of segments I must visit to select the items.

Suggested Approach

My initial idea has been to combined the 2 result sets and produce a list of

Segment ID, NumberOfItemsRequiredInSegment

I would then select 25 items from each query, giving preference to those in a segments with the most NumberOfItemsRequiredInSegment.

I know this would not be optimal but would be an easy to implement heuristic.

Questions

1) I suspect this is a standard combinational problem, but I don’t recognise it.. perhaps multiple knapsack, does anyone recognise it?

2) Is there a better (easy-ish to impliment) heuristic or solution – ideally in TSQL?

Many thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:59:22+00:00Added an answer on June 11, 2026 at 2:59 pm

    This might also not be optimal but i think would at least perform fairly well.

    Calculate this set for query 1.

    Segment ID, NumberOfItemsRequiredInSegment
    

    take the top 25, Just by sorting by NumberOfItemsRequiredInSegment. call this subset A.

    take the top 25 from query 2, by joining to A and sorting by “case when A.segmentID is not null then 1 else 0, NumberOfItemsRequiredInSegmentFromQuery2”.

    repeat this but take the top 25 from query 2 first. return the better performing of the 2 sets.

    The one scenario where i think this fails would be if you got something like this.

    Segment   Count Query 1    Count Query 2
    A         10               1
    B         5                1
    C         5                1
    D         5                4
    E         5                4
    F         4                4
    G         4                5
    H         1                5
    J         1                5
    K         1                10
    

    You need to make sure you choose A, D, E, from when choosing the best segments from query 1. To deal with this you’d almost still need to join to query two, so you can get the count from there to use as a tie breaker.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question somehow addresses the problem, but not from the side I'm looking for.
Thanks for looking on this problem. I have a page that is totally valid
I am looking for a simple answer for this problem... I have a UITextView
I'm looking for the generally accepted/best solution to this problem. Problem I have a
I'm looking for an elegant pattern to solve this problem: I have several user
I am looking for the easiest way to solve this problem. I have a
I realize there are several solutions to this problem. I am looking for advice
I have been looking at this problem for the last couple of days and
I have heard about this problem and now I am looking for more specific
I've been looking for solutions to this problem for far too long considering how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.