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

  • Home
  • SEARCH
  • 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 1094929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:02:39+00:00 2026-05-17T00:02:39+00:00

Situation Say I have the following: a table items a table lists to which

  • 0

Situation
Say I have the following:

  • a table items
  • a table lists to which these items can be linked
  • a table users

Condition: a list can belong to all or one specific user

What I’d like to do is create “global” lists that exist for ever user. But there should be a possibility to “overwrite” this global list with a user-specific one. Example for a random user:

  • a global list called books
  • a user-specific list cds

Now when retrieving the lists for this user I should get both the global books lists and the user-specific cds list. But what if this user has a specific list of books?

  • a global list called books
  • a user-specific list books
  • a user-specific list cds

So now it should retrieve the user-specific list called books instead of the global list, and of course the user-specific cds list.

Possible solutions
The easiest thing would be something like this:

table: lists
- id
- name
- userId

If the userId IS NULL it would mean that it’s a global list, but when it’s NOT NULL it belongs to a specific user. So the first example would be for userId = 1:

id  name    userId
1   books   NULL
2   cds     1

To retrieve the lists for this user:

SELECT * FROM lists WHERE userId = 1 OR userId IS NULL

But then I’m stuck at the next part:

id  name    userId
1   books   NULL
2   cds     1
3   books   1

Here the first list “books” is a global one, but this user also has a user-specific list “books”. It is possible to ignore the global list in this case, and only return the user-specific one?

Another possibility would be to create a lists_users table, linking all the users to all the global lists, and deleting this link whenever a user-specific list is created with the same name as one of these global lists. This doesn’t seem very efficient though, and a lot more work to maintain when adding new users.

Question:
What’s the best and most efficient way to set this up in the database, so that I can easily retrieve the correct lists for a specific user?

  • 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-17T00:02:41+00:00Added an answer on May 17, 2026 at 12:02 am

    For your current design you can get user’s list in the following way:

    SELECT * FROM lists 
    WHERE userId = 1 
    UNION ALL
    Select * from lists g 
    Where userId IS NULL
    AND NOT EXISTS (SELECT 1 from lists l where g.name = l.name and userid = 1)
    

    i.e. select user-specific lists and global not-redefined by user

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

Sidebar

Related Questions

I have the following situation I have a couple of table rows within a
I have the following situation: excel-like application, that is accessible from internet. 2 users
I have the following multi-table inheritance situation: from django.db import Models class Partner(models.Model): #
I have the following situation: I have site A, which has it's Mercurial repo,
Hypothetical situation: let's say I have a 3rd party .net assembly being used in
A general architecture question in Sitecore 6... Let’s say we have a situation where
Is it right to use a private constant in the following situation: Say I
I have a situation in which the ideal relationship, I believe, would involve Value
I have the following requirement: - I have many (say 1 million) values (names).
I have the following situation: I have a few hundred resources at my disposal

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.