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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:26:29+00:00 2026-05-20T14:26:29+00:00

I want to union records from 2 tables, sort them, and read TOP rows

  • 0

I want to union records from 2 tables, sort them, and read TOP rows from result set.

T1
--------
Id, Timestamp, Text1

T2
--------
Id, Timestamp, Text2

With SQL it can be done this way:

SELECT TOP 10 * FROM
(
    SELECT 
        [Timestamp], 
        [Text1] 

    FROM 
        T1

    UNION

    SELECT 
        [Timestamp], 
        [Text2]

    FROM 
        T2
) as x

ORDER BY [Timestamp]

Q: How can I do that task using EF linq?

  • 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-20T14:26:30+00:00Added an answer on May 20, 2026 at 2:26 pm

    You need an anonymous type with the same property names and types before you can do an Union operation:

    var t1List = from a in allT1
            select new
            {
                TimeStamp = a.TimeStamp,
                Text = a.Text1
            };
    var t2List = from b in allT2
            select new
            {
                TimeStamp = b.TimeStamp,
                Text = b.Text2
            };
    
    var result = t1List.Union(t2List).OrderBy(ab => ab.TimeStamp).Take(10);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to union the result of two sub-queries (say SUB1 and SUB2). The
I need to select records from 2 tables, one called cities and one called
I want to display two records. For eg select * FROM users WHERE user_id
I want to get the union of 2 nested lists plus an index to
i want to build a pointer to a Qt Slot: union { void (*set_slot)(unsigned
How can I using group by with union in T-SQL? I want to group
Want the function to sort the table by HP but if duplicate HPs then
I have SELECT * FROM Table1 WHERE Col1 IN(4,2,6) I want to select and
I have two tables that contain data from different temperature sensors: Table1 _TimeStamp Temperature
I've two tables which have following columns: Now I want have a SQL query

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.