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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:54:21+00:00 2026-06-07T08:54:21+00:00

I have my MAIN table T1 from which I am doing select of many

  • 0

I have my MAIN table T1 from which I am doing select of many fields:

ID
1000

I have table T2:

ID      SERVICE
1000    IPTV
1000    VOIP

I have table T3:

ID      DEVICE
1000    MODEM
1000    ROUTER
1000    DVC

I want to JOIN T1 with T2 or T3 which can but also and might not have values at all !!!!
When they have values I want to have in SELECT number of records of maximum number of records from T2 or T3. So in this case T3 has 3 records which is maximum and I want 3 records in SELECT. (in case that T2 has 3 records that would be maximum in case that T3 has 2 records)

But in my SELECT statement I am having 5 records which I do not want. What is the correct expression for that? My below query returns 5 records (I want 3)

select t1.id,t2.service,t3.device
from t1
left outer join T2 on t1.id=t2.id
left outer join T3 on t1.id=t3.id
  • 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-07T08:54:22+00:00Added an answer on June 7, 2026 at 8:54 am
    SELECT
        t1.id
      , t2.service
      , t3.device
    FROM
            t1
        LEFT JOIN
                ( SELECT
                      ROW_NUMBER() OVER (PARTITION BY id ORDER BY service) AS rn
                    , id
                    , service
                  FROM
                      t2
                ) AS t2
            FULL JOIN 
                ( SELECT
                      ROW_NUMBER() OVER (PARTITION BY id ORDER BY device) AS rn
                    , id
                    , device
                  FROM
                      t3
                ) AS t3
              ON  t3.id = t2.id
              AND t3.rn = t2.rn
          ON COALESCE(t2.id, t3.id) = t1.id ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main table called M1 which consists of Ids of three individual
I have two tables with hierarchyid fields, one of which is a staging table
Ok, here's the condensed form. I have three main tables to draw data from:
I have main table called 'Employee' and another slave table called 'EmployeeTypes' that has
I have a main Table, with several child tables. TableA and TableAChild1 and TableAChild2.
I have a structure where the main table is USER, other tables include CATEGORY
I have 2 tableViews, the first one is the Main table and the second
I have a main SQL Server A that data is inserted into. The table
I have a SQL Server database with 500,000 records in table main . There
I have four different tables, one main SPECIAL table containing only id's that reference

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.