Jump to content

Recommended Posts

First off Hi All,

I need help with a query.

 

I have 2 tables users and sessions

in users I have (user, status, ip)

in sessions I have (sessionid, user, stoptime)

 

In users there user is unique and in sessions the sessionid is unique.

 

I what to select the max sessionid for all users in users table

I worte this query but it takes forever to run and never seems to finish, the sessions table has about 50000 rows.

 

SELECT MAX(sessionid) FROM sessions s1 
WHERE s1.users IN 
(SELECT u1.user from users u1) group by s1.username

this returns all the correct sessions for each users

 

SELECT * FROM sessions s2 WHERE s2.sessionid IN (SELECT MAX(sessionid) FROM sessions s1 
WHERE s1.users IN 
(SELECT u1.user from users u1) group by s1.username)

This runs forever

 

I am looking for a query that returns the results

user,status,ip,sessionid,stoptime

 

I have not included the join in the code as I an batteling with getting the correct info back from the above codes

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/209005-mysql-query-help/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.