This is what I need to do:
1. Get the records from the DB
2. Do NOT get a record if "field A" is repeated.
3. Grab the first record from that with the latest ID.
Here's my table:
When a new user comes, a record is added. Now, this could be the SAME user, his 2nd visit and his PREVIOUS record is still there. Well guess what? I'll need to display a list of active users, and I do NOT want to display REPEAT users (the key is their User ID and IP).
id (Primary Key, Auto Increment)
I have done this successfully with the following query:
But now, I want to select the LATEST record (using the ID as reference). So I need to get the latest record, because this query only gets the FIRST record.
SELECT u.userid, u.username, u.userlevel, s.session_user_logged_in, s.session_user_ip, s.session_user_last_updated, s.session_user_last_page
FROM users u, session s
WHERE u.userid = s.session_user_id
GROUP BY u.username, s.session_user_ip
Does anyone understand? It's hard to explain...
See, I will be displaying this info in a table on a page, and I need to get the latest info from the user, not old info! No one wants to see their OLD info now do they?
I tried using:
After the GROUP BY clause, but it didn't work...