N
N
Nikita Dergachov2022-03-03 19:03:08
MySQL
Nikita Dergachov, 2022-03-03 19:03:08

How to get all but the first entries with duplicate users?

There is a table of the form It is uuid, user_id, update_at(timestamp)
necessary to get all the records in which it repeats user_idand in which update_at < MAX(update_at)with the current user_id

So far I figured out how to get records with repetitions, but I update_athaven’t figured out how to filter by yet

SELECT * FROM table WHERE user_id IN (SELECT user_id from table group by user_id having count(*) > 1)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2022-03-03
@vanillathunder

SELECT DISTINCT `t1`.*
  FROM `table` AS `t1`
  JOIN `table` AS `t2`
    ON `t2`.`user_id` = `t1`.`user_id`
      AND `t2`.`update_at` > `t1`.`update_at`

M
Michael, 2022-03-03
@Akela_wolf

Add to WHERE: AND update_at >= :date
And the actual value of the parameter is easiest to pull out with a separate request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question