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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:40:07+00:00 2026-05-14T20:40:07+00:00

Here is my scenario Table 1: GID || Info1 Table 2: GID || Tb1GID

  • 0

Here is my scenario

Table 1: GID || Info1

Table 2: GID || Tb1GID (refers
to GID of Table1) || Info2

Table 3: GID || Info3

Table 4: GID || Tb2GID (refers to
GID of Table2 || Tb3GID (refers to
Table3 GID || Value

Now I have to build an sql query to get the value, given a particular Info1, Info2, Info3.
Essentially, I have to get the GID, of table 1 using info1, GID of table to , by mapping info2 and GID of table 1. And then get the GID of table 3 using info 3. And combine these to GIDs to get the value in table 4.

What is the most optimal way of constructing an sql query for this one?

  • 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-14T20:40:07+00:00Added an answer on May 14, 2026 at 8:40 pm

    Just join the tables on the id:s and match the info values in the condition:

    select
      t4.Value
    from
      [Table 1] as t1
      inner join [Table 2] as t2 on t2.Tb1GID = t1.GID
      inner join [Table 4] as t4 on t4.Tb2GID = t2.GID
      inner join [Table 3] as t3 on t3.GID = t4.Tb3GID
    where
      t1.Info1 = @Info1 and
      t2.Info2 = @Info2 and
      t3.Info3 = @Info3
    

    This communicates most clearly how the relations work, giving the query planner the best information to work with.

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

Sidebar

Related Questions

Here is a simple scenario with table characters: CharacterName GameTime Gold Live Foo 10
Here's my scenario: I've got a table of (let's call them) nodes. Primary key
Here's the scenario: I have 2 tables: CREATE TABLE dbo.API_User ( id int NOT
Here is the scenario: SQL Server 2000 (8.0.2055) Table currently has 478 million rows
Here is the scenario: I have a table that records the user_id, the module_id,
Here is the scenario: You have a Persons table with a one-to-many relationship with
Here's the scenario: I have a table with 3 columns: 'KeyColumn', 'SubKeyColumn' and 'BooleanColumn',
Here's the scenario: TABLE 1 (client table. imported into sql server via a csv
Here's the scenario: The selections in DropDownList are bound from a DB Table listing
Here is my scenario: I have a single table with 2 columns. ID and

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.