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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:46:33+00:00 2026-06-16T09:46:33+00:00

I have 2 tables, for example let’s assume that this is the data: users

  • 0

I have 2 tables, for example let’s assume that this is the data:

users table:

 ------------------------------
|   user_id     |   username    |
 ------------------------------
| 1             | danny         |
| 2             | george        |
| 3             | lana          |
| 4             | kim           |
| 5             | tim           |
 ------------------------------

users_logins table:

     -----------------------------------------------
    | record_id | user_id   |   recorder            |
     -----------------------------------------------
    | 1         | 3         | 2012-11-06 04:18:26   |
    | 2         | 3         | 2012-11-06 04:31:05   |
    | 3         | 2         | 2012-11-06 03:44:22   |
    | 4         | 1         | 2012-11-06 04:18:58   |
    | 5         | 1         | 2012-11-06 04:30:15   |
    | 6         | 3         | 2012-11-06 04:31:05   |   X
    | 7         | 1         | 2012-11-06 05:53:47   |
    | 8         | 1         | 2012-11-06 05:55:15   |   X
    | 9         | 4         | 2012-11-06 05:59:31   |
    | 10        | 4         | 2012-11-06 06:12:55   |   X
     -----------------------------------------------

I want to show 3 recent logged in users, so the result will show only the rows that marked with X right to them, or in words unique recent logins.

How would the query look like?

  • 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-16T09:46:34+00:00Added an answer on June 16, 2026 at 9:46 am

    I think this is what you want.

    var resentLogedInUsers =
        users
            .Join(
                users_logins,
                u => u.user_id,
                l => l.user_id,
                (u, l) => new
                                {
                                    User = u,
                                    Login = l.recorder
                                })
            .GroupBy(j => j.User)
            .Select(l => new {User = l.Key, LastLogin = l.Max(d => d.Login)})
            .OrderByDescending(r => r.LastLogin)
            .Take(3);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume that I have 2 tables: Human, Car. Table Car has some columns
I have a function that updates several tables. As an example, let's say it
I have some tables that benefit from many-to-many tables. For example the team table.
I have the next task. Let's assume that we have below tables in a
AdventureWorks tables have Insert/Update/Delete anomalies. Isn't that considered bad design? Let's take for example
I have multiple tables in my database. Let's say the table users looks like
For example, let's say I have the following two tables: Table1: Id ---- 1
Can I have an identity (unique, non-repeating) column span multiple tables? For example, let's
I have two tables, for example: Table A Table B ======= ======= Name |
Here's a problem I experience (simplified example): Let's say I have several tables: One

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.