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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:55:23+00:00 2026-06-14T13:55:23+00:00

I have three tables. Table Data contains data for individual parts that come from

  • 0

I have three tables.

  • Table Data contains data for individual parts that come from a
    “data.txt” file.
  • Table Limits contains the limits for the Data table
    from a “limits.txt” file.
  • Table Files is a listing for
    each individual .txt file above.

So the “Files” table looks like this. As you can see it is a listing of each file that exists. The LimitsA file will contain the limits for every Data file of type A.

ID  File_Name  Type  Sub-Type
1   DataA_10   A     10
2   DataA_20   A     20
3   DataA_30   A     30
4   LimitsA    A     NONE
5   DataB_10   B     10
6   DataB_20   B     20
7   LimitsB    B     NONE

The “Data” table looks like this. The File_ID is the foreign key from the “Files” table. Specifically, this would be data for DataA_10 above:

ID  File_ID  Dat1  Dat2  Dat3... Dat20
1   1        50    52    53 
2   1        12    43    52 
3   1        32    42    62 

The “Limits” table looks like this. The File_ID is the foreign key from the “Files” table. Specifically, this would be data for LimitsA above:

ID  File_ID  Sub-Type  Lim1  Lim2
1   4        10        40    60    
2   4        20        20    30    
3   4        30        10    20    

So what I want to do is JOIN the correct limits from the “Limit” table to the data from the corresponding “Data” table. Each row of DataA_10 would have the limits of “40” and “60” from the LimitsA table. Unfortunately there is no way to directly link the limits table to the data table. The only way to do this would be to look back to the files table and see that LimitsA and DataA_10 are of type A. Once I link those two together I then need to specifically only grab the Limits for Sub-Type 10.

In the end I would like to have a result that looks like this.

Result:

ID  File_ID  Dat1  Dat2  Dat3... Dat20  Lim1  Lim2
1   1        50    52    53             40    60
2   1        12    43    52             40    60
3   1        32    42    62             40    60

I hope this is clear enough to understand. It seems to me like an issue of joining more than 2 tables, but I have been unable to find a suitable solution online as of yet. If you have a solution or any advice it would be greatly appreciated.

  • 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-14T13:55:25+00:00Added an answer on June 14, 2026 at 1:55 pm

    Your ‘Files’ table is actually 2 separate (but related) concepts that have been merged. If you break them out using subqueries you’ll have a much easier time making a join. Note that joining like this is not the most efficient method, but then again neither is the given schema…

    SELECT Data.*, Limits.Lim1, Limits.Lim2
    FROM (SELECT * FROM Files WHERE SubType IS NOT NULL) DataFiles
    JOIN (SELECT * FROM Files WHERE SubType IS NULL) LimitFiles
      ON LimitFiles.Type = DataFiles.Type
    JOIN Data 
      ON DataFiles.ID = Data.File_ID
    JOIN Limits
      ON LimitFiles.ID = Limits.File_ID
      AND DataFiles.SubType = Limits.SubType
    ORDER BY Data.File_ID
    

    UPDATE

    To be more specific on how to improve the schema: Currently, the Files table doesn’t have a clear way to differentiate between Data and Limit file entries. Aside from this, the Data entries don’t have a clear link to a single Limit file entry. Although both of these can be figured out as in the SQL above, such logic might not play well with the query optimizer, and certainly can’t guarantee the Data-Limit link that you require.

    Consider these options:

    • Instead of linking to a ‘Limit’ file via Type, link directly to a Limit entry Id. Set a foreign key on that link to ensure the expected Limit entry is available.
    • Separate the ‘Limit’ entries from the ‘Data’ entries by putting them in a separate table.
    • Create an index on the foreign key. For that matter, add indices for all foreign keys – SQL Server doesn’t do this by default.

    Of these, I would consider having a foreign key as essential, and the others as modest improvements.

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

Sidebar

Related Questions

I have a MySQL query that: gets data from three tables linked by unique
I have a Microsoft SQL Server 2008 query that returns data from three tables
I have three tables of data: table: cars [10,000 rows] table: planes [2,000 rows]
Ok, here's the condensed form. I have three main tables to draw data from:
I have a table in my data base that has three columns: Screen, Icon,
I have three mysql tables that I would like to extract some information from,
I have three tables. The first two tables have similar data but they come
So... assuming i have a database with three tables: Table clients Table data and
Let's say I have a tab-delimited text file that contains data arranged in columns
I have 3 tables that are unrelated (related that each contains data for a

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.