Get users Last Login Data
Get users Last Login Data
(OP)
Hi Everyone,
I had this thread on SQL Server forum and was told since I am using MySQL to ask for this request here:
I am a newbie getting started with SQL and did some search online but so far have not been able to solve and gather the data I need.
I need to get all users last login data so I may then delete user accounts that not logged in for a long time as I have reached the max license usage for this system.
I have found the Opinio SQL table and drilled down to table OPS_UserAttribute where I can see column named AttributeName which when I run a search on this table using MySQL the data results in last login instead of showing me the actual date of last login (below a screenshot of data I am looking for)
.
I ran below SQL command but all I got was data as 0 or 1:

Thank you in advance for your support!
I had this thread on SQL Server forum and was told since I am using MySQL to ask for this request here:
I am a newbie getting started with SQL and did some search online but so far have not been able to solve and gather the data I need.
I need to get all users last login data so I may then delete user accounts that not logged in for a long time as I have reached the max license usage for this system.
I have found the Opinio SQL table and drilled down to table OPS_UserAttribute where I can see column named AttributeName which when I run a search on this table using MySQL the data results in last login instead of showing me the actual date of last login (below a screenshot of data I am looking for)

I ran below SQL command but all I got was data as 0 or 1:

Thank you in advance for your support!
RE: Get users Last Login Data
Do you need to also get some other fields?
RE: Get users Last Login Data
Correct I need to match this "Last Login" info with the users which I believe is under the table OPS_User which shows column "UserId" on both tables
RE: Get users Last Login Data
CODE
This shows what you've queried before (*) but adds a column at the end with a readable timestamp (FROM_UNIXTIME(`LongValue`)). It also orders the result so the oldest logins appear first (ASCending).
Caution should be exercised here. Limit your SQL activity to SELECT; not DELETE or UPDATE. Without fully understanding the structure of this system, removing accounts in SQL may wreck the application, especially if other data is related to these accounts in other tables. Use this only to list users, but remove the users within the web application.
RE: Get users Last Login Data
I ran below Code and I got many 1969 year date since "LongValue" was "0" which means user never logged in so no timestamp (that's ok)... then I changed order by to "DESC" and I can see "NULL" value under timestamp. As an example for 1 userid 10553 system shows date of last login as: May 20, 2021 2:10 PM but comes up as "Null" value running below code (looks like Code was not able to convert the "LongValue":
CODE -->
RE: Get users Last Login Data
RE: Get users Last Login Data
CODE -->
RE: Get users Last Login Data
Did a research on FROM_UNIXTIME showing null values and I got it working, basically because unix time is in seconds and data shows stored it in milliseconds requiring to divide by 1000:
CODE -->
RE: Get users Last Login Data
Whoops. I was not paying attention to the length of those strings. Well done!
RE: Get users Last Login Data
>as both "opinio.OPS_User" and "opinio.OPS_UserAttribute" tables have the unique
>column match "Userid"
...
From opinio.OPS_UserAttribute, opinio.OPS_User
WHERE opinio.OPS_UserAttribute.Userid = opinio.OPS_User.Userid
or use aliases for your tables:
...
From opinio.OPS_UserAttribute A, opinio.OPS_User U
WHERE A.Userid = U.Userid
or
SELECT *, FROM_UNIXTIME(`LongValue` /1000) AS `timestamp`,
(Select Login From opinio.OPS_User Where UserId = opinio.OPS_UserAttribute.UserId) AS TheUser
FROM opinio.OPS_UserAttribute
WHERE `AttributeName` = 'last login'
ORDER BY `LongValue` DESC
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson
RE: Get users Last Login Data
I went ahead and added another field from OPS_user table:
CODE -->
Thank you as well spamjim!
Not sure if it is possible to do, during the sql code, but when I export the data into a csv file the "timestamp" value gets gibberish which I have to manually do a custom "Format Cell" on the column and set as "yyyy-mm-dd" to get data correctly in excel as "2016-04-04"
RE: Get users Last Login Data
Also, you may get a better performance doing this instead:
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson
RE: Get users Last Login Data
I did a research as you suggested and ended as (will as well do some edit as you suggested to have a better performance):
CODE -->
RE: Get users Last Login Data
CODE -->
Thank you everyone!