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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:26:47+00:00 2026-05-26T05:26:47+00:00

I have 2 tables which share a common table of types The type table

  • 0

I have 2 tables which share a common table of “types”
The type table is as follows:

CREATE TABLE [ModifierType](
[ModifierTypeID] [int] NOT NULL,
[Code] [varchar](10) NOT NULL,
[Name] [varchar](50) NOT NULL,)

CREATE TABLE [UserRequest](
[UserRequestID] [int] NOT NULL,
[Name] [varchar](50) NOT NULL,)

CREATE TABLE [Matrix](
[MatrixID] [int] NOT NULL,
[Name] [varchar](50) NOT NULL,)

CREATE TABLE [UserRequestModifier](
[UserRequestModifierID] [int] NOT NULL,
[UserRequestID] [int] NOT NULL,
[ModifierTypeID] [int] NOT NULL,
[Value] [varchar](50) NOT NULL,)

CREATE TABLE [MatrixModifier](
[MatrixModifierID] [int] NOT NULL,
[MatrixID] [int] NOT NULL,
[ModifierTypeID] [int] NOT NULL,
[Value] [varchar](50) NOT NULL,)

The others are a UserRequestModifier table, and a “MatrixModifier” table which contains rules for determining access a request should be provisioned. Matrix in this case just refers to a set of rules that will grant access to a specific application or group. These two tables each have a ModifierTypeID which will link the two and a value field that will be used for finding matches.

However, each UserRequest/Matrix (parents to the modifier tables) can each have multiple modifier records.

What I need to do, is find all the Matrix records for which the UserRequestModifiers meets all the MatrixModifier requirements. Basically, I want to ignore any MatrixIDs that have even 1 modifier value that does not match ANY of the UserRequestModifier values.

So far I have a query that will do it, but it seems a bit backwards to me, because I’m having to first find all the MatrixIDs that the UserRequestModifiers do not meet the requirements in a subselect. Then getting the records that are NOT IN those results as follows:

SELECT 
    UR.[UserRequestModifierID]
    ,UR.[ModifierTypeID]        
    ,UR.[Value] AS [URValue]
    ,MM.[Value] AS [MMValue]
    ,MM.[MatrixModifierID]
    ,MM.[MatrixID]
    ,MM.[ModifierTypeID]        
    ,M.[MatrixID]       
FROM
    AMP.[UserRequestModifier] AS UR
LEFT OUTER JOIN AMP.[MatrixModifier] AS MM
    ON (MM.[ModifierTypeID] = UR.[ModifierTypeID])
LEFT OUTER JOIN AMP.[Matrix] AS M
WHERE
    UR.[UserRequestID] = @UserRequestID
    AND M.[MatrixID] IS NOT NULL
    AND M.[MatrixID] NOT IN
        (SELECT
            DISTINCT MM.[MatrixID]      
        FROM
            AMP.[UserRequestModifier] AS UR
        LEFT OUTER JOIN AMP.[MatrixModifier] AS MM
            ON (MM.[ModifierTypeID] = UR.[ModifierTypeID])
        WHERE
            UR.[UserRequestID] = @UserRequestID
            AND (CASE WHEN LTRIM(RTRIM(MM.[Value])) = LTRIM(RTRIM(UR.[Value])) THEN 1 ELSE 0 END) = 0
            AND MM.[MatrixID] IS NOT NULL)
ORDER BY M.[MatrixID], MM.[ModifierTypeID]

I know this is a bit hard to follow, but I’m hoping someone can point out something obvious I’m missing.

  • 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-26T05:26:47+00:00Added an answer on May 26, 2026 at 5:26 am

    For MS SQL Server:

    -- ====================
    -- sample data
    -- ====================
    DECLARE @ModifierType TABLE (
    [ModifierTypeID] [int] NOT NULL,
    [Code] [varchar](10) NOT NULL,
    [Name] [varchar](50) NOT NULL)
    
    DECLARE @UserRequest TABLE (
    [UserRequestID] [int] NOT NULL,
    [Name] [varchar](50) NOT NULL)
    
    DECLARE @Matrix TABLE (
    [MatrixID] [int] NOT NULL,
    [Name] [varchar](50) NOT NULL)
    
    DECLARE @UserRequestModifier TABLE (
    [UserRequestModifierID] [int] NOT NULL,
    [UserRequestID] [int] NOT NULL,
    [ModifierTypeID] [int] NOT NULL,
    [Value] [varchar](50) NOT NULL)
    
    DECLARE @MatrixModifier TABLE (
    [MatrixModifierID] [int] NOT NULL,
    [MatrixID] [int] NOT NULL,
    [ModifierTypeID] [int] NOT NULL,
    [Value] [varchar](50) NOT NULL)
    
    insert into @modifiertype
    select 1, '1', 'modname1'
    union all
    select 2, '2', 'modname2'
    union all
    select 3, '3', 'modname3'
    union all
    select 4, '4', 'modname4'
    union all
    select 5, '5', 'modname5'
    union all
    select 6, '6', 'modname6'
    
    insert into @userrequest
    select 1, 'ureq1'
    union all
    select 2, 'ureq2'
    union all
    select 3, 'ureq3'
    union all
    select 4, 'ureq4'
    
    insert into @matrix
    select 1, 'm1'
    union all
    select 2, 'm2'
    union all
    select 3, 'm3'
    union all
    select 4, 'm4'
    
    
    insert into @userrequestmodifier
    select 1, 1, 1, 'val1'
    union all
    select 2, 1, 2, 'val2'
    union all
    select 3, 1, 3, 'val3'
    union all
    select 4, 1, 4, 'val4'
    union all
    select 5, 2, 5, 'val5'
    union all
    select 6, 1, 5, 'val5'
    union all
    select 7, 1, 6, 'val6'
    union all
    select 8, 1, 6, 'val6'
    
    
    
    
    insert into @matrixmodifier
    select 1, 1, 1, 'val1'
    union all
    select 2, 2, 2, 'val2'
    union all
    select 3, 3, 3, 'val'
    union all
    select 4, 2, 4, 'val4'
    union all
    select 5, 2, 5, 'val5'
    union all
    select 6, 3, 4, 'val4'
    union all
    select 7, 13, 4, 'val4'
    
    declare @UserRequestID int
    set @UserRequestID = 1
    
    
    -- ====================
    -- solution
    -- ====================
    select
        userrequestmodifierid,
        modifiertypeid,
        urvalue,
        mmvalue,
        matrixmodifierid,
        mmmatrixid,
        mmatrixid
    from
    (
        select 
            urm.userrequestmodifierid,
            urm.modifiertypeid,
            urvalue = urm.value,
            mmvalue = mm.value,
            mm.matrixmodifierid,
            mmmatrixid = mm.matrixid,
            mmatrixid = m.matrixid,
            f = max(case when urm.value != mm.value then 1 end) over (partition by mm.matrixid)
        from @userrequestmodifier urm
        left join @matrixmodifier mm on
            urm.modifiertypeid = mm.modifiertypeid
        left join @matrix m on
            m.matrixid = mm.matrixid
        where urm.userrequestid = @userrequestid
    ) t
    where f is null or mmatrixid is null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables which looks something like this Table Queue int ID; string
I have 2 tables which in simplified form look like this: Products( id: int,
I have two tables which are used to store details of different types of
Hi I want to have two tables each have an INT id column which
I have two related classes which share a common interface and are both stored
I have several custom UITableViewCell , which share a lot of common subelements. I
I have a database in which the tables do not have primary/foreign keys. This
I have two tables which I want to join together using a left outer
I have two tables which have some transactional stuff stored in them. There will
I have a MySQL Left Join problem. I have three tables which I'm trying

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.