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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:22:31+00:00 2026-06-11T17:22:31+00:00

I have user with name, location, created_at as important fields in table. I want

  • 0

I have user with name, location, created_at as important fields in table.
I want to retrieve for each user the latest location,i.e, I want something like this:

username    location       created_at
abc         New York       2012-08-18 16:18:57
xyz         Mexico city    2012-08-18 16:18:57
abc         Atlanta        2012-08-11 16:18:57

only input is UId(1,2) array of userids.please help me to accomplish this.I just want to know how to write query using active record query interface.

  • 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-11T17:22:32+00:00Added an answer on June 11, 2026 at 5:22 pm

    Generally, this should be a standard way to solve this kind of problems:

    SELECT l1.user, l1.location
    FROM locations l1
    LEFT JOIN locations l2 ON l1.user = l2.user AND l2.created_at > l1.created_at
    WHERE l2.id IS NULL
    

    The idea is to join the table with itself, and find those rows which don’t have any row with the same user and greater created_at.

    Of course, you should have (user, created_at) index on your table.

    Now you should see how would that be represented in AR interface.

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

Sidebar

Related Questions

Currently I am doing this: I have text that looks like: Hello ${user.name}, this
I have a mysql table with three columns: username, location, timestamp. This is basically
I want to retrieve the user's location and then show a link that points
I have a Location model with fields: Location(id: integer, name: string, address: string, latitude:
I have a Model like so: # == Schema Information # # Table name:
I have a user control which displays the currently logged in user's name. I
I have the following model: class User: name = models.CharField( max_length = 200 )
I have mail server configuration data (server - user name - password - port)
On websites where you have to enter a user name and password, I notice
Following scenario: I have user object: ... @Column(name = TITLE) private String title; @NotNull

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.