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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:16:42+00:00 2026-06-15T14:16:42+00:00

I’m getting a bit lost in making a query that performs a certain look

  • 0

I’m getting a bit lost in making a query that performs a certain look up.
I have the first part of the query going, which returns me all accounts that have missing some entries on their account. Now I need to filter this subset further based on their last login attempt.

The table structures are as follows:

  • The users table contains all user information. We only care about users under project_id 33.
  • The users_account_list contains all accounts a user has. We only care about users NOT having an entry for service 50.
  • The users_login_logs contains all login attempts for a user.

The original query I have this this:

SELECT u.id,
       u.login, 
       u.email, 
       u.nickname,
       b.station_login AS "additionals.station_login",
       a.id AS "user_account_list.id",
       a.game_id AS "user_account_list.game_id",
       a.game_uid AS "user_account_list.game_uid",
       c.created_at AS "last login"
FROM users u
LEFT JOIN user_account_list a ON u.id = a.user_id AND a.game_id = 50
LEFT JOIN user_additionals b ON u.id = b.id
LEFT JOIN user_login_logs c ON u.id = c.user_id
WHERE u.project_id = 33
AND u.verified_at IS NOT NULL
AND (a.id IS NULL OR a.game_id IS NULL OR a.game_uid IS NULL)
AND (b.station_login IS NULL OR b.station_login = '')
ORDER BY c.created_at DESC

This returns me all users that have been registered under project_id 33, and do not have an entry for game_id 50, and have no information stored in their additional info table. Optional, but not relevant, Just limits the data returned. It does give me multiple rows per user back , sorted according their latest login date.

What I need is to get only 1 row per user returned with their LATEST login date. I tried replacing the ORDER BY with GROUP by u.id but this gives me the oldest result back, not the latest.

How can I:

  • Limit the rows returned to only 1 row per user
  • Make sure the row is based on the latest login attempt of the user.

EDIT:

This is what the query currently returns:

+----+-------+-----------------+----------+---------------------------+----------------------+---------------------------+----------------------------+---------------------+
| id | login | email           | nickname | additionals.station_login | user_account_list.id | user_account_list.game_id | user_account_list.game_uid | last login          |
+----+-------+-----------------+----------+---------------------------+----------------------+---------------------------+----------------------------+---------------------+
|  1 | usrnm | someon@mail.com | Nickname |                           |                 NULL |                      NULL | NULL                       | 2012-10-19 00:00:00 |
|  1 | usrnm | someon@mail.com | Nickname |                           |                 NULL |                      NULL | NULL                       | 2012-10-18 00:00:00 |
|  1 | usrnm | someon@mail.com | Nickname |                           |                 NULL |                      NULL | NULL                       | 2012-10-17 00:00:00 |
+----+-------+-----------------+----------+---------------------------+----------------------+---------------------------+----------------------------+---------------------+
3 rows in set (0.08 sec)
  • 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-15T14:16:43+00:00Added an answer on June 15, 2026 at 2:16 pm

    You need to replace your ORDER BY by a GROUP by u.id as you tried but you also need in your SELECT to indicate that you want the last date in the group so you need to replace

    c.created_at AS "last login"
    

    by

    MAX(c.created_at) AS "last login"
    

    This will return only one line per user thanks to the GROUP BY and you will only select the latest date for each user thanks to MAX()

    Edit: I think you should avoid using alias column names with spaces inside to avoid mistakes

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.