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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:26:38+00:00 2026-05-17T19:26:38+00:00

This may have been asked before and I just can’t find it. I have

  • 0

This may have been asked before and I just can’t find it.

I have a one to many relationship in the database on a few tables.

  • table1
  • table2
  • table3

table2 – table3 is the 1-many relationship

here’s a mock of what I have:

select
table1.id
table1.Column
table2.Column2
-- I want all entries here from table 3 here as well
From table1 t1
left outer join table2 t2 on t2.ID = t1.ID
left outer join join table3 t3 on t3.ID2 = t2.ID2

Is it possible to also select all of the entries that belong to table3 in this query without specifying a sub-query in the select statement?

Also, does this look right? As I’ve said in the past I’m really new to SQL, thus my sucky code…

EDIT

Sorry guys I misspoke. I need a single column from each of the rows that should be in table3

select
table1.id,
table1.Column,
table2.Column2,
-- I'm going to need a subquery here aren't I...?
table3.columnFromRrow1,
table3.columnFromRrow2,
table3.columnFromRrow3
From table1 t1
left outer join table2 t2 on t2.ID = t1.ID
left outer join join table3 t3 on t3.ID2 = t2.ID2
  • 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-17T19:26:38+00:00Added an answer on May 17, 2026 at 7:26 pm
    ;WITH cte AS
         ( SELECT table1.t1id,
                  table1.t1col,
                  table2.t2col,
                  table3.t3col,
                  ROW_NUMBER() OVER (PARTITION BY t1id,t1col,t2col 
                                     ORDER BY table3.id) AS RN
         FROM     table1 t1
                  LEFT OUTER JOIN table2 t2
                  ON       t2.ID = t1.ID
                  LEFT OUTER JOIN
                  JOIN table3 t3
                  ON       t3.ID2 = t2.ID2
         )
    SELECT 
       t1id,
       t1col,
       t2col,
       MAX(CASE WHEN RN=1 THEN t3col END) AS columnFromRrow1,
       MAX(CASE WHEN RN=2 THEN t3col END) AS columnFromRrow2,
       MAX(CASE WHEN RN=3 THEN t3col END) AS columnFromRrow3
    FROM cte
    WHERE RN<=3
    GROUP BY t1id,t1col,t2col
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may have been asked before, but I could not find the answer. I
this question may have been asked many times, but could not find any suitable
This question may well have been asked before but I didn't find anything whilst
This question has been asked before, but I can't find any answers that have
this may have been asked before, but I could not find it. Suppose I
This question may have been asked before, but I couldn't find an answer to
This question may have been asked before, but I had trouble finding an answer,
This has / may have been asked before, but, as far as I remember,
This question may have been asked before, but I'm starting to get into game
This question may have been asked already - but unfortunately, I could not find

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.