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

  • Home
  • SEARCH
  • 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 8839795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:19:02+00:00 2026-06-14T10:19:02+00:00

I am trying to select a table from my database based on top 5

  • 0

I am trying to select a table from my database based on top 5 values from another table and met a roadblock.

here is the version without the top 5 values :

from d in Deals
from f in FacebookUserCategories
from s in SubCategories
where s.FacebookCategoryId == f.FacebookCategoryId
&& f.FacebookUserId == 1437585390
orderby f.Count descending
select d

However , what i need is to select Deals based on the top 5 Ids from SubCategories table, meaning i have to use a Take operator.

The below linq will help me achieve this :

(from f in FacebookUserCategories
 from s in SubCategories
 where s.FacebookCategoryId == f.FacebookCategoryId
 orderby f.Count descending
 select s.Id).Take(5)

Is there anyway for me to select the Deals table which has a SubCategoryId as a join from here?

Just to recap…i could write the sql.. it would be like this :

SELECT t1.* FROM Deal t1
INNER JOIN (
SELECT TOP 5 t2.Id FROM FacebookUserCategory , SubCategory t2
WHERE FacebookUserId = '1437585390'
AND FacebookUserCategory.FacebookCategoryId = t2.FacebookCategoryId 
ORDER BY Count DESC) tbl
ON t1.SubCategoryId = tbl.Id
  • 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-14T10:19:03+00:00Added an answer on June 14, 2026 at 10:19 am

    Try this, Use Join for all 3 tables, You use Join for only 2 tables, why not use Join for 3rd table also.

    var result = from d in deals
                 let top5Counts =
                (from f in FacebookUserCategories
                 join s in SubCategories on f.FacebookCategoryId equals s.FacebookCategoryId
                 where f.FacebookUserId == 1437585390
                 orderby f.Count descending
                 select s.Id).Take(5)
                where top5Counts.Contains(d.SubCategoryId.Value)
                select d;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to copy data from table into another by using a SELECT
After dynamically creating a client-side table based on SELECT information retrieved from MySql database,
I'm trying to figure out how to select data from a MySQL table based
I'm trying to select a specific row from a database based on a string
I'm trying to select from table, excluding where id is something, say 7. I
i'm trying to do this query: SELECT * FROM TABLE WHERE value1='THIS'S AN EXAMPLE'.
I am trying to create a statement as follows: SELECT * FROM table WHERE
I am trying to select rows from a table where one of the (NVARCHAR)
I am trying to select the last record from a table in MySQL using
I'm trying to select most recent date from one table (invoice) to a customer

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.