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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:18:51+00:00 2026-06-04T17:18:51+00:00

I am currently working on a very big project which involves many-to-many and one-to-many

  • 0

I am currently working on a very big project which involves many-to-many and one-to-many relationships… There are a few tables to work with and I can’t figure out how to do what I want.
Here is my first table (Objects Table) :

+-----------+------+-------+
| Object ID | Name | Value |
+-----------+------+-------+   The Object ID is a foreign Key to another table.
|     1     | Aaaa |   2   |   The Name is unique for each Object ID.
|     1     | Bbbb |   5   |
|     2     | Aaaa |   15  |
|     2     | Bbbb |   3   |
+-----------+------+-------+

My second table is the following (Users Table) :

+---------+------+-------+
| User ID | Name | Value |
+---------+------+-------+    The User ID is also a foreign Key, there are  
|    7    | Aaaa |  10   |    multiple rows with the same User ID. 
|    7    | Bbbb |   7   |
+---------+------+-------+

I have a third table showing the relationship between the other tables

+---------+-----------+
| User ID | Object ID |
+---------+-----------+ There are no identical rows in this table. 
|    7    |     1     |
+---------+-----------+

I am trying to find all the objects in the Objects Table that the user has. The user needs to have ALL the object names. And for each Name, the value of the User must be at least the value of the Object for that name.

For example here, the user has Aaaa with a value of 10 and Bbbb with a value of 7. So he has ALL of the names of the Object 1 and his values are greater than or equal to those values.
Therefore he can have Object n° 1.
For object 2, the User doesn’t have enough of Aaaa, so he can’t have the object 2.

I know how to get all of the rows of Objects Table where the User has the Name and a big enough value with Inner Joins :

SELECT Users.User ID, Objects.Object, Objects.Name ID FROM Objects
INNER JOIN Users
ON Objects.Name = Users.Name AND Objects.Value <= Users.Value

But the problem is that it would return the following :

+---------+-----------+------+
| User ID | Object ID | Name |
+---------+-----------+------+
|    7    |     1     | Aaaa |
|    7    |     1     | Bbbb |
|    7    |     2     | Bbbb |
+---------+-----------+------+

The problem is that I want to get rid of the last row here since the user doesn’t have enough of Aaaa for Object 2.

Any help would be greatly appreciated !
Thanks

  • 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-04T17:18:52+00:00Added an answer on June 4, 2026 at 5:18 pm

    You could use a not exists clause to demand that none of the matching objects has a higher value than the user’s value:

    select  Users.User ID, Objects.Object, Objects.Name ID 
    from    Objects o
    join    Users u
    on      o.Name = u.Name 
    where   not exists
            (
            select  *
            from    Objects o2
            where   o2.Name = u.Name
                    and o2.Value > u.Value
            )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a project in which I need a very simple editor
I am VERY new to PHP, I'm currently working on a service, part which
I am working on a big .NET project. I am currently creating an automated
I am currently working on a very specialized PHP framework, which might have to
I am currently working on an application which will audit computers, and one of
I'm currently working on a quite small project. I'm basing my work on smtpd.py
I'm currently working on a very short project on Prolog, and just got stuck
Currently I'm prototyping search with Lucene.Net-2.0-004 on a web application. It's working very well,
Currently, I am working on the very beginnings of a user database in MySQL
Currently working on a VBScript to automate some of the dirty PST ingestion work

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.