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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:24:55+00:00 2026-06-07T20:24:55+00:00

I have this query: (from a in SickDays join b in Class.Where(p => p.ID

  • 0

I have this query:

(from a in SickDays
    join b in Class.Where(p => p.ID == myId) on a.Class_ID equals b.ID
    join c in Student on a.Student_ID equals c.ID
    group a by new { c.Name, c.Order } into ac
    select new { Count = ac.Count(), Name = ac.Key.Name, Order = ac.Key.Order }
).OrderBy(f => f.Order)

This returns:

Count | Name | Order
    3 | Dave |     a
    2 | John |     b
    7 | Sally|     c

However I’d like it to return this:

Count | Name | Order
    3 | Dave |     a
    2 | John |     b
    7 | Sally|     c
    0 | Mark |     d
    0 | Betty|     e

UPDATE:
This is what Students, Classes and SickDays look like using @sixlettervariables example:

var Students = new List<Student>()
{
    new Student { Id = 1, Name = "Al", Order = 'a' },
    new Student { Id = 2, Name = "Betty", Order = 'b' },
    new Student { Id = 3, Name = "Charles", Order = 'c' },
};

var Classes = new List<Class>()
{
    new Class { Id = 1, Title = "A100" },
    new Class { Id = 2, Title = "A200" },
};

var SickDays = new List<SickDay>()
{
    new SickDay { Id = 1, StudentId = 1, ClassId = 1 },
    new SickDay { Id = 2, StudentId = 1, ClassId = 1 },
    new SickDay { Id = 3, StudentId = 1, ClassId = 2 },
    new SickDay { Id = 4, StudentId = 1, ClassId = 2 },
    new SickDay { Id = 5, StudentId = 2, ClassId = 1 },
};

Ok the above is now correct, so sorry for the confusion!

  • 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-07T20:24:57+00:00Added an answer on June 7, 2026 at 8:24 pm

    This is known as a Left Outer Join. In this case, every Student is required even if they have no Sick Days. So, we would start with the students, perform a left outer join with the sick days, and then return the count of the classes which matched the ID you had specified:

    var query =
        from s in Students
        join d in SickDays on s.ID equals d.Student_ID into gj
        from sd in gj.DefaultIfEmpty()
        group sd by new { s.Name, s.Order } into gg
        select
            new
            {
                Name = gg.Key.Name,
                Order = gg.Key.Order,
                Count = gg.Count(x => x != null && x.Class_ID == myId)
            };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query: sess.createQuery(from Box b join b.items bi order by bi.name).list() It
I have this query: SELECT * FROM sample INNER JOIN test ON sample.sample_number =
i have this sql query select * from table where name like ? but
I have this linq query : (from rapportBase in New_RapportReferencementBases join rapportExtensionAll in New_RapportReferencementExtensionBases
I have this query: select id from mytable where contains(all_text,'('||?||' within name)*2, ('||?||' within
I have this database query SELECT * FROM (`metadata` im) INNER JOIN `content` ic
I have this query select * from alldistros t1 LEFT join origin t2 on
I have this simple query select * from users where name = 'User1' I'd
I have this query: (from r in gServiceContext.CreateQuery(opportunity) join c in gServiceContext.CreateQuery(contact) on ((EntityReference)r[new_contact]).Id
I have this query: SELECT hit.timestamp,hit.id,config.Name,hit.meter_id,levels.LevelName, pos.sm_pos , hit.hit_value FROM pos,hit,controllers,levels,config WHERE hit.id=config.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.