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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:21:37+00:00 2026-06-18T16:21:37+00:00

I have the following table designed already. Now the new requirement is i need

  • 0

I have the following table designed already.

Now the new requirement is i need to show some Category for all the
tenants. Also each tenant should able to add their new Category into
the Master Category. So they can see all master + their specific
categories

Tenant Table

TenantId
Name

Group Table

GroupId
Name

Category Table

CategoryId
Name

TenantXCategory

TenantId
CategoryId

What changes i can do in above tables to achieve it? I tried this below

Modified Category table to below.

Category Table

CategoryId
Name
TenantId NULL // This indicates tenant specific category

Add a unique key for TenantId and Name

Then queried

SELECT *
  FROM Category where TenantId = 1
  UNION
SELECT *
  FROM Category where TenantId IS NULL

But the problem is if two tenant only want to see a particular
Category, I need to add a new row with other TenantId in Category
table. This mean i am creating duplicate entry in a lookup table. Any
suggestion to achieve the new requirement?

  • 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-18T16:21:38+00:00Added an answer on June 18, 2026 at 4:21 pm

    So, a tenant A may see:

    • (1) master categories,
    • (2) categories that belong to tenant A,
    • (3) categories which belong to another tenant and which the other tenant explicitly allowed tenant A to see

    Your present schema seems to satisfy the requirements. In particular, the first two rules can indeed be implemented using a nullable TenantId column in the Category table, where NULL would stand for a master category and a non-NULL value would reference the creator/owner of the category and thus signify a tenant-specific category. (I might rename the column to something like OwnerTenantId for better clarity, but that might be just me.)

    To retrieve only master categories or those that belong to the specified tenant, you could use the query you’ve posted in your question or this one (which will probably yield an identical execution plan to your query’s):

    SELECT
      CategoryId,
      CategoryName,
      CASE
         WHEN TenantId = @TenantId    THEN 'Mine'
         WHEN TenantId IS NULL        THEN 'Master'
      END AS Ownership
    FROM Category
    WHERE TenantId = @TenantId
       OR TenantId IS NULL
    ;
    

    To implement the third rule, you could use your TenantXCategory table to store categories available to tenants in addition to those that are accessible using the first two rules. That is, if tenant M permits tenant N to see some of tenant M’s categories, the categories’ Ids would be inserted into TenantXCategory along with tenant N’s Id.

    So, to query all categories available to a particular tenant, you could do something along the lines of the following:

    SELECT
      c.CategoryId,
      c.CategoryName,
      CASE
         WHEN c.TenantId = @TenantId    THEN 'Mine'
         WHEN c.TenantId IS NULL        THEN 'Master'
         WHEN tc.CategoryId IS NOT NULL THEN 'Someone else''s'
      END AS Ownership
    FROM Category c
    LEFT JOIN TenantXCategory tc
      ON tc.CategoryId = c.CategoryId AND tc.TenandId = @TenantId
    WHERE c.TenantId = @TenantId
       OR c.TenantId IS NULL
       OR tc.CategoryId IS NOT NULL
    ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following Table with records for ActivityLog: ID, UserId, Category, Created 1 11
I have the following table that lists all awarded cups: Name: Cups Columns: Month,
I have following table Id | Status | date ------------------- 1 | Onsite |2007
Imagine I have following table: NAME DATE OTHER_CONTANT 'A' '2012-06-05' 'baz' 'A' '2012-06-04' 'bar'
Let's say I have following table like this <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0
I have following CSS: table tbody tr:last-child td { padding-top: 7px; border-bottom: 0; }
I have the following table drop table names; create table names( name varchar(200), surname
I have the following table: Order Product Price Quantity Description Order1 Product1 12 1
I have the following table UserID | User knows -------------------- a | b a
I have the following table: ID | JobID | Data | ResultType --------------------------------- 1

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.