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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:45:01+00:00 2026-05-24T05:45:01+00:00

I have the following in SQL: SELECT * FROM (SELECT Teikoku_Sections.Section_ID, Teikoku_Sections.Section_Name, Teikoku_Sections.Section_Code, Teikoku_Sections.Show_In_Menu

  • 0

I have the following in SQL:

SELECT * FROM (SELECT Teikoku_Sections.Section_ID, Teikoku_Sections.Section_Name, Teikoku_Sections.Section_Code, Teikoku_Sections.Show_In_Menu FROM Teikoku_Sections WHERE Teikoku_Sections.Show_In_Menu = 1) AS Sections
LEFT OUTER JOIN (SELECT Teikoku_Divisions.Division_ID, Teikoku_Divisions.Division_Name, Teikoku_Divisions.Division_Code, Teikoku_Divisions.Section_ID, Teikoku_Divisions.Show_In_Menu FROM Teikoku_Divisions WHERE Teikoku_Divisions.Show_In_Menu = 1) AS Divisions
ON Sections.Section_ID = Divisions.Section_ID;

Which performs a left outer join on the two tables Teikoku_Sections and Teikoku_Divisions and join the visible items from both tables together.

The tables have the structure:

Teikoku_Section:
Section_ID int,
Section_Name nvarchar(50),
Section_Code int,
Show_In_Menu bit

Teikoku_Divisions:
Division_ID int,
Division_Name nvarchar(50)
Division_Code int,
Section_ID int, <== The ID of the parent section
Show_In_Menu bit

I would like to end up with a table showing all sections and divisions which have Show_In_Menu true, but in some cases there might not be any divisions corresponding to a section, hence the LEFT OUTER JOIN.

I just can’t get my head round to how to do this in linq to sql.

So far I have:

//Get All Visible sections
    IQueryable<Teikoku_Section> visibleSections = from section in db.Teikoku_Sections where section.Show_In_Menu select section;
    //Get all visible divisions
    IQueryable<Teikoku_Division> visibleDivisions = from division in db.Teikoku_Divisions where division.Show_In_Menu select division;
    //Join the two together
    IQueryable menuItems = visibleSections.GroupJoin(visibleDivisions, section => section.Section_ID,
        division => division.Section_ID, (section, divisions) => new
        {
            Section_ID = section.Section_ID,
            Section_Name = section.Section_Name,
            Division_ID = divisions.Select(d => d.Division_ID),
            Division_Name = divisions.Select(d => d.Division_Name),
        });

    return menuItems;

Which doesn’t quite work… I think I might be missing a SelectMany(), but I just can’t figure where or how to put it.

  • 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-24T05:45:02+00:00Added an answer on May 24, 2026 at 5:45 am

    Look into DefaultIfEmpty (http://msdn.microsoft.com/en-us/library/bb355419.aspx)

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

Sidebar

Related Questions

I have the following query sql query: select * from Articles ar left join
I have the following SQL statement: SELECT * FROM cars car LEFT JOIN (SELECT
I have the following sql query SELECT * FROM jos_jcalpro_events AS e LEFT JOIN
I have the following sql statement: SELECT COUNT(table2.programName), table2.programName FROM table1 LEFT JOIN table2
I have the following SQL: SELECT * FROM [Database].dbo.[TagsPerItem] INNER JOIN [Database].dbo.[Tag] ON [Tag].Id
I have a following SQL QUERY: SELECT articles.name, articles.price, users.zipcode FROM articles INNER JOIN
I have the following SQL: SELECT * FROM Name INNER JOIN ( SELECT 2
Let's say I have the following SQL query: SELECT * FROM employee INNER JOIN
I have the following sql query: UPDATE (SELECT * FROM table_A INNER JOIN table_B
I have the following SQL-statement: SELECT DISTINCT name FROM log WHERE NOT name =

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.