Is there a SQL query for users created in OIM. There are no dates provided while creating users in OIM, But we need to find the users on the basis of their creation date.
Select * from usr where to_date(usr_create)>to_date('01-Jun-2016', 'DD-MON-YYYY');
Related
I have two Mysql database dumps (DB1_10.10.2019 and DB2_10.02.2020). I created a custom query in DB1_10.10.2019 for getting the user details and made a 'report1'.
DB1_10.10.2019:
SELECT DISTINCT(...)
FROM ...
WHERE...
ORDER BY ...
For now, I have created a table called Table1 and stored the results.
INSERT INTO Table1(...,...,...)
SELECT DISTINCT(...)
FROM ...
WHERE...
ORDER BY...
Let's say after 4 months I want to get the user details, but this time I do not want users in report1. I want only new users. Can anyone please suggest a solution on how to achieve this?
I referred to the following site: https://www.mysqltutorial.org/mysql-minus/ and tried the following method:
SELECT
id
FROM
t1
LEFT JOIN
t2 USING (id)
WHERE
t2.id IS NULL;
The above query works only if we have two tables in the same DB. But in my case, I have two DB's.
MySQL version: 5.7.19
If the database is on the same machine and your user can access both, just enter the database name in the query as follows:
SELECT
`DB1_10.10.2019`.t1.id
FROM
`DB1_10.10.2019`.t1
LEFT JOIN
`DB2_10.02.2020`.t2 USING (id)
WHERE
`DB2_10.02.2020`.t2.id IS NULL;
Here you can find some examples
I have about 180000 users in my wp_users database. Most of them are old and dormant. I fear this is slowing down my site (is this likely?). I want to safely delete old accounts along with all their associated data.
Using bulk delete plugins does not work as they timeout with so many users. I want to do it with mysql instead. By searching around I have found the following code:
DELETE
wp_users,
wp_usermeta
FROM
wp_users
INNER JOIN wp_usermeta ON wp_users.ID = wp_usermeta.user_id
WHERE
meta_key = 'wp_capabilities' AND
meta_value LIKE '%subscriber%' AND
user_registered < NOW() - INTERVAL 360 DAY
The code works but is it safe and is it the best way? Will it delete their associated meta data etc.
Please first take a backup of your database before running this query
Yes You can use this query to delete the user & user_meta data but if your theme/plugin saving users data in some others table(if you are using any plugin that store user data in other table) than you have to look again in database and modify your query according to this..
I need to find which user did not login today.
I have 3 tables (users, logs, absence), the log just registers that a user identified by userID has logged in with a timestamp of the login.
So im trying run a script every night that creates an entry in absence with the users and the time of the absence.
I want to compare userID from table(users) with table(logs) and find which user is missing today by looking at the timestamp in the log.createdAt column.
the problem here is "today" , i can find examples here on how to just compare the two tables like this.
SELECT userID
FROM users
WHERE NOT EXIST (
SELECT userID
FROM logs
WHERE userID = users.userID
)
or like this
SELECT userID
FROM users LEFT JOIN logs ON users.userID = logs.userID
WHERE logs.UID is null
But this just returns the people who have never been logged at all.
I'm using sequelize raw query so either a raw query answer or sequelize answer is good
SELECT userID
FROM users
LEFT JOIN logs ON users.userID = logs.userID and DATE(log.createdAt )=DATE(SYSDATE())
WHERE logs.UID is null
Just try above code hope this will helps.
I have a users table and an edits table (showing who performed changes on their own or someone else's profile).
In the edits table, the editor and editee are listed using their userid, which is the unique id in the users table.
I would like to create the query:
Select users.username (the editee), users.username (the editor) from users
inner join edits on users.id = edits.editee_id
How would I create a subquery to pull the editor's name?
Thanks
You need to join the users table twice.
SELECT whatever,
editor.username AS editor_username,
editee.username AS editee_username
FROM edits
JOIN users AS editor ON edits.editor_id = editor.id
JOIN users AS editee ON edits.editee_id = editee.id
See what's going on? You use the users table twice, and give it a different alias in each use.
I've got four tables. The structure of these tables is shown below (I am only showing the relevant column names).
User (user_id)
User_RecordType (user_id, recordType_id)
RecordType (recordType_id)
Record (recordType_id, record_timestamp, record_value)
I need to find the most recent record_value for each RecordType that a given user has access to. Timestamps are stored as seconds since the epoch.
I can get the RecordTypes that the user has access to with the query:
SELECT recordType_id
FROM User, User_RecordType, RecordType
WHERE User.user_id=User_RecordType.user_id
AND User_RecordType.recordType_id=RecordType.recordType_id;
What this query doesn't do is also fetch the most recent Record for each RecordType that the user has access to. Ideally, I'd like to do this all in a single query and without using any stored procedures.
So, can somebody please lend me some of their SQL-fu? Thanks!
SELECT
Record.recordType_id,
Record.record_value
FROM
Record
INNER JOIN
(
SELECT
recordType_id,
MAX(record_timestamp) AS `record_timestamp`
FROM
Record
GROUP BY
recordType_id
) max_values
ON
max_values.recordType_id = Record.recordType_id
AND
max_values.record_timestamp = Record.record_timestamp
INNER JOIN
User_RecordType
ON
UserRecordType.recordType_id = RecordType.recordType_id
WHERE
User_RecordType.user_id = ?