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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:07:33+00:00 2026-06-11T23:07:33+00:00

I have 2 tables that represent 2 different model simulations. As back ground info

  • 0

I have 2 tables that represent 2 different model simulations. As back ground info the 2 models are trying to simulate the same thing but modelA tries to represent very specific attributes whereas and modelb tries to model a broader range. Table A has n rows which is larger than the m rows in tableB. I’m trying to create a table with the same number of rows (n) as table A where I can see which modelA_IDs relate to modelB_IDs.

TableA:

ModelA_ID  region height weight
1          1       25      7.1            
2          1       70      7.1            
3          1       10      7.2            
4          1       30      7.3
5          1       35      7.4
6          2       30      7.1

TableB:

ModelB_ID  region min_height max_height min_weight max_weight
9001       1        0             50      7.1        7.3    
9002       1        51            100     7.1        7.3
9003       1        0             100     7.4        7.5
9004       2        0             100     7.1        7.5

So in the example above I should end with something along the lines of

ModelA_ID  ModelB_ID    
1        9001            
2        9002            
3        9001            
4        9001      
5        9003     
6        9004

Region is not unique in either table. If it were I think I would join on that, something along the lines of

SELECT  TableA.ModelA_ID TableB.ModelB_ID 
FROM TableA
inner JOIN TableA
ON TableA.region =TableB.region
where 
TableA.height >= TableB.min_height
and TableA.height <= TableB.max_height
and TableA.weight >= TableB.min_weight
and TableA.weight <= TableB.max_weight

However region is not a unique key so I can’t do that!

New to SQL as of a couple of days ago but come from a cshell background but new job has sql only policy 🙁

Any ideas? It is not something that has to be repeated often so efficiency is not key.

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-11T23:07:35+00:00Added an answer on June 11, 2026 at 11:07 pm

    However region is not a unique key so I can’t do that!

    It is not mandatory that the JOIN columns must be primary keys in their respective tables.

    SELECT 
        TableA.ModelA_ID,
        TableB.ModelB_ID 
    FROM 
        TableA
        JOIN TableB
        ON TableA.region = TableB.region
    WHERE 
        TableA.height >= TableB.min_height
    AND TableA.height <= TableB.max_height
    AND TableA.weight >= TableB.min_weight
    AND TableA.weight <= TableB.max_weight
    

    Results of the above query are:

    ModelA_ID   ModelB_ID
    ----------- -----------
    1           9001
    3           9001
    4           9001
    2           9002
    5           9003
    6           9004
    
    (6 row(s) affected)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables in my database schema that represent an entity having a
Here's my situation.. Suppose you have the following model entities, which represent single tables
I've got an ASP.NET MVC (VB) project with two models that represent two different
Here's my problem: I have three tables that represent a many to many relationship
In my Yii application, I have a model that represents siteconfig table and have
I have two tables that link together through an id one is submit_moderate and
I have some tables that I'm joining in a query with Postgres (9). However,
I have two tables that have virtually identical content and very similar structure. They
I have two tables that I want to join together. Table1 Year, ID, Theme,
How to I represent the following datamodel in sql tables. I have 3 entities,

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.