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 6158195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:55:00+00:00 2026-05-23T20:55:00+00:00

I have Users , Positions and Licenses . Relations are: users may have many

  • 0

I have Users, Positions and Licenses.

Relations are:

  • users may have many licenses
  • positions may require many licenses

So I can easily get license requirements per position(s) as well as effective licenses per user(s).

But I wonder what would be the best way to match the two sets? As logic goes user needs at least those licenses that are required by a certain position. May have more, but remaining are not relevant.

I would like to get results with users and eligible positions.

PersonID PositionID
1        1          -> user 1 is eligible to work on position 1
1        2          -> user 1 is eligible to work on position 2
2        1          -> user 2 is eligible to work on position 1
3        2          -> user 3 is eligible to work on position 2
4        ...

As you can see I need a result for all users, not a single one per call, which would make things much much easier.


There are actually 5 tables here:

create table Person ( PersonID, ...)
create table Position (PositionID, ...)
create table License (LicenseID, ...)

and relations

create table PersonLicense (PersonID, LicenseID, ...)
create table PositionLicense (PositionID, LicenseID, ...)

So basically I need to find positions that a particular person is licensed to work on. There’s of course a much more complex problem here, because there are other factors, but the main objective is the same:

How do I match multiple records of one relational table to multiple records of the other. This could as well be described as an inner join per set of records and not per single record as it’s usually done in TSQL.

I’m thinking of TSQL language constructs:

  • rowsets but I’ve never used them before and don’t know how to use them anyway
  • intersect statements maybe although these probably only work over whole sets and not groups
  • 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-05-23T20:55:00+00:00Added an answer on May 23, 2026 at 8:55 pm

    Final solution (for future reference)

    In the meantime while you fellow developers answered my question, this is something I came up with and uses CTEs and partitioning which can of course be used on SQL Server 2008 R2. I’ve never used result partitioning before so I had to learn something new (which is a plus altogether). Here’s the code:

    with CTEPositionLicense as (
        select
            PositionID,
            LicenseID,
            checksum_agg(LicenseID) over (partition by PositionID) as RequiredHash
        from PositionLicense
    )
    select per.PersonID, pos.PositionID
    from CTEPositionLicense pos
        join PersonLicense per
        on (per.LicenseID = pos.LicenseID)
    group by pos.PositionID, pos.RequiredHash, per.PersonID
    having pos.RequiredHash = checksum_agg(per.LicenseID)
    order by per.PersonID, pos.PositionID;
    

    So I made a comparison between these three techniques that I named as:

    1. Cross join (by Andriy M)
    2. Table variable (by Petar Ivanov)
    3. Checksum – this one here (by Robert Koritnik, me)

    Mine already orders results per person and position, so I also added the same to the other two to make return identical results.

    Resulting estimated execution plan

    1. Checksum: 7%
    2. Table variable: 2% (table creation) + 9% (execution) = 11%
    3. Cross join: 82%

    I also changed Table variable version into a CTE version (instead of table variable a CTE was used) and removed order by at the end and compared their estimated execution plans. Just for reference CTE version 43% while original version had 53% (10% + 43%).

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

Sidebar

Related Questions

Lets say I have around 1,000,000 users. I want to find out what position
Suppose I have a table of users. Something like: ID integer, USER text, POSITION
:-) I have this script, which find a users position taken from the number
I have table Users which contains columns: id, name, points, extra_points. How can I
In my application, users have a list of items that they can put in
Within the realm of this problem I have 3 entities: User Position License Then
I have table with positions tbl_positions id position 1 Driver 2 Lobby 3 Support
I have table with positions tbl_positions id position 1 Driver 2 Lobby 3 Support
I have created a button CSS class that uses background images with different positions
I have a scene written in Java 3d, where the user's viewing position is

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.