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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:02:20+00:00 2026-06-05T14:02:20+00:00

I am trying to do a left outer join on three tables. I know

  • 0

I am trying to do a left outer join on three tables. I know there is a way to do it in one variable but I haven’t been able to figure it out. Instead I have performed two separate left outer joins and then did a left out join on those. Here is my code for that:

var outerJoin1 =    

    (from h in resultHours  
    join u in results on new {h.PhysicalUnitId, h.MonthNum} equals new {u.PhysicalUnitId, u.MonthNum} into outer
    from grouping in outer.DefaultIfEmpty() 
    select new {timeKey = h, Key = grouping});

var outerJoin2 =    

    (from h in resultHours
    join s in serviceHrsResults on new {h.PhysicalUnitId, h.MonthNum} equals new {s.PhysicalUnitId, s.MonthNum} into outer2
    from grouping in outer2.DefaultIfEmpty()
    select new {timeKey = h, Key = grouping});

var outerJoin = 

    (from a in outerJoin1
    join b in outerJoin2 on new {a.timeKey.PlantId, a.timeKey.MonthNum} equals new {b.timeKey.PlantId, b.timeKey.MonthNum} into outer
    from grouping in outer.DefaultIfEmpty()
    select new{timeKey = a, Key = grouping}).Distinct();

I have tried putting the above together in one variable I can’t get it to work. Here is what I have tried:

var outerjoin =

    from h in resultHours
    join u in results on new {h.PhysicalUnitId, h.MonthNum} equals new {u.PhysicalUnitId, u.MonthNum} into outer
    from grouping in outer.DefaultIfEmpty()
    from hr in resultHours
    join s in serviceHrsResults on new {hr.PhysicalUnitId, hr.MonthNum} equals new {s.PhysicalUnitId, s.MonthNum} into outer2
    from grouping in outer2.DefaultIfEmpty()
    select new {timeKey = h && timeKey = hr, Key = grouping};

The problem with this is the two groupings conflict. i’m pretty sure I just need a single grouping right before the select but cannot figure out how to use the “grouping in” and include both outer.DefaultIfEmpty() and outer2.DefaultIfEmpty().

I would appreciate it if someone could enlighten me.

  • 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-05T14:02:21+00:00Added an answer on June 5, 2026 at 2:02 pm

    You are using duplicate range variable ids – you’ve got 2x grouping.
    – Which grouping is it that you want in the result set ?
    – What is this line expected to achieve?
    timeKey = h && timeKey = hr – how do you want to combine those in the projection ?

    I would try the query below, but I’ve changed the select part of it as your combined version doesn’t make sense to me.

    Let me know if it at all works for you as without data it’s not easy to test this, so I can’t be sure that the new version is fine.

    var outerjoin =
        from h in resultHours
        join u in results on new {h.PhysicalUnitId, h.MonthNum} equals new {u.PhysicalUnitId, u.MonthNum} into outer
        from grouping1 in outer.DefaultIfEmpty()
        //from hr in resultHours
        join s in serviceHrsResults on new {grouping1.PhysicalUnitId, grouping1.MonthNum} equals new {s.PhysicalUnitId, s.MonthNum} into outer2
        from grouping2 in outer2.DefaultIfEmpty()
        select new {timeKey = h, Key1 = grouping1, Key2 = grouping2};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a three different tables that I'm trying to join up correctly but
I'm trying to LEFT JOIN two tables, to get a list of all rows
I'm trying to do a left join in subsonic 3 using linq but it
I'm trying to conditionally join one master event table to three others depending on
I'm trying to use a join on three tables query I found in another
While trying an outer join query I noticed that changing one condition from the
Elloo, I have two doctrine entities and am trying to do left join however
I'm trying to check the left co-ordinate of a div but it's not returning
I am trying to do a LEFT JOIN in Hibernate Query Language, in MySQL
So I have three tables I am trying to pull data from with the

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.