I have table that records logins for users. I’m having trouble finding a query that will efficiently pull all unique users who have not had a login timestamp before a date of my choosing. I can easily find this information if I query per-user.
Fields are essentially:
id, username, login, logout
I need a query that will find all usernames that have no logout timestamp in 2011-11. The fact that there are multiple join events for a single easier is what’s confusing me.
Exclude all users that had at least one
logoutat the date in question with a negated semi join (EXISTS) like this:This will not multiply rows from
users. If2011-11is supposed to signify the month of November 2011:Additional answer to question in comments
Flag the first login of users in the log
You can do that, but there are many more rows in table
logthan in tableusers. I would advise instead: