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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:36:02+00:00 2026-05-21T11:36:02+00:00

I have three tables (people, clients_people, clients) that would be joined using SELECT *

  • 0

I have three tables (people, clients_people, clients) that would be joined using

SELECT * FROM people
LEFT JOIN clients_people ON people.id = clients_people.person_id
LEFT JOIN clients ON clients_people.client_id = client.id

Each client record has a location – L1, L2, and L3 (client.location = ‘L1’, etc.). I want the ability to store exclude locations for each person; e.g. I would like to define people.id=1 to exclude clients.location = ‘L1’ and clients.location = ‘L3’ in a new query.

I have two solutions right now.

  1. Add column client_location_exclude to the people table and store ‘L1,L3’ in people.id=1 record.
  2. Allow for negative integers to be stored in clients_people.client_id that define the exclusions; e.g. clients_people.client_id = -1 defines an L1 exclusion, clients_people.client_id = -2 defines an L2 exclusion, etc.

Are either of these good solutions (pros/cons)? Is there a better (best) solution?

The data is going to be used in a Ruby on Rails application and a PHP (no framework) application; but from my perspective, I’m more interested in how the tables should be structured to hold and easily utilize the exclusion of locations.

Thank you.

  • 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-21T11:36:02+00:00Added an answer on May 21, 2026 at 11:36 am

    The normal form would be to use.. a table (!).. to store the relationship. It is after all a relational database system. If would also make sense if you have a location table, to be able to add referential integrity to the exclusion list. Storing ‘L1,L3’ is bad for not being normalised, and also for being hard to work with down the track (you need string splitting functions to access individual elements all the time).

    The table would look like

    people_location_exclusions: people_id, location_id
    

    A query could look like this

       SELECT *
         FROM people
    LEFT JOIN clients_people
           ON people.id = clients_people.person_id
    LEFT JOIN clients
           ON clients_people.client_id = client.id
    LEFT JOIN people_location_exclusions
           on people_location_exclusions.people_id = people.id
          and people_location_exclusions.location_id = clients.location_id
        WHERE people_location_exclusions.people_id is NULL
    

    The LEFT JOIN + WHERE clause removes clients from the result even if the client is linked through client-people

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

Sidebar

Related Questions

I have currently created a facebook like page that pulls notifications from different tables,
I have an inheritance hierarchy with overlap. The system knows about People that can
So I have two tables in this simplified example: People and Houses. People can
i want to find a number of clients from certain dates before and after
I have a process that imports a daily file of product registrations, and adds
I have a mySQL table with list of people and phone numbers. There are
I have a query where I need to select text with a colon inside,
I have been thinking and learning a lot about forms lately trying to add
I'm currently doing a summer job and I have to extend an existing program.
I am learning about encryption methods and I have a question about MD5. I

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.