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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:27:03+00:00 2026-05-11T02:27:03+00:00

Newbie to LINQ, and trying to write the following query… select f.Section_ID, f.Page_ID, f.SortOrder,

  • 0

Newbie to LINQ, and trying to write the following query…

select    f.Section_ID,    f.Page_ID,    f.SortOrder,    f.Type from  (   select      Section_ID,      min(SortOrder) as minSortOrder   from      ContentPages    group by      Section_ID ) as x  inner join    ContentPages as f on      f.Section_ID = x.Section_ID and      f.SortOrder = x.minSortOrder; 

Notes:

  • ‘Section’ has many ‘ContentPages’
  • Sections are ordered by a ‘SortOrder’ field
  • ContentPages are also ordered by a ‘SortOrder’ field

Table: Section
Section_ID….Name…….SortOrder
….1………One……….1……
….2………Two……….3……
….3………Three……..2……

Table: ContentPage
Page_ID…….Section_ID…….Title…………..SortOrder
….11………….1………. Page One………….1……
….12………….1………..Page Two………….3……
….13………….2………..Page Three………..2……
….16………….2………. Page Four…………4……
….17………….2………..Page Eight………..5……
….18………….1………..Page Ten………….6……

The above query could possibly be written another way, so here’s what I’m trying to do:

  • I need to return a list of the first ContentPage within each Section (when sorted by ContentPage.SortOrder)
  • Sort results by Section.SortOrder
  • Show Section.Name (join on Section_ID?) in the result as well

Last 2 points are not covered by the sql query above and are more of a ‘nice to have’…

Desired Result
Page_ID…….Section_ID…SectionName…..Title…………..SortOrder
….11………….1………One……… Page One………….1……
….13………….2………Two……….Page Three………..2……

Any help is appreciated. Thanks!

  • 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. 2026-05-11T02:27:03+00:00Added an answer on May 11, 2026 at 2:27 am

    Here’s my first attempt at it:

    from sectionPage in pages group sectionPage by sectionPage.Section_ID into sectionGroup join page in pages on sectionGroup.Key equals page.Section_ID where page.SortOrder == sectionGroup.Min(p => p.SortOrder) orderby page.SortOrder select page; 

    What happens is first we create a group on the section id so that we can get the minimum sort order later. Next, we join a new reference to pages in on the section id, and filter by SortOrder being the minimum from the section group. Note, for simple expressions like the Min() call, I prefer the inline lambda expression over another query.

    Finally, we add an orderby to order the pages, and we return the page (note you can change this to certain fields if you prefer).

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

Sidebar

Ask A Question

Stats

  • Questions 62k
  • Answers 62k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer jQuery makes things like this so trivial that you just… May 11, 2026 at 10:17 am
  • added an answer Changing to the asp.net web site model won't have any… May 11, 2026 at 10:17 am
  • added an answer Have you considered simply using System.Drawing namespace? For example: System.Drawing.Color… May 11, 2026 at 10:17 am

Related Questions

Newbie to LINQ, and trying to write the following query... select f.Section_ID, f.Page_ID, f.SortOrder,
I'm a newbie to LINQ in C# and am using it to read in
I'm a LINQ to XML newbie, and a KML newbie as well; so bear
I'm a newbie when it comes to LINQ... I have an IEnumerable generic list
Just getting started with Linq to SQL so forgive the newbie question. I'm trying
I'm a newbie to pgsql. I have few questionss on it: 1) I know
I am a newbie to WPF and have a couple of questions about WPF
I'm a newbie to swing development. I have a swing app that needs to
So I'm a newbie to TDD, and I successfully created a nice little sample
I'm a total newbie to SVN and haven't been able to find an answer

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.