V
V
Vladimir Galynsky2016-08-29 14:51:50
MySQL
Vladimir Galynsky, 2016-08-29 14:51:50

How to display entries by day with matching values?

Hello. I have a table {id, idUsr, name, time}. Users appear every day. I need to find records that are duplicated, that is, when two records of the same user are in one day ( by idUsr ). I sent a request like this, but it will display only for the current day, but how can I do it for a month?

SELECT id, idUsr, name, time FROM users WHERE DATE(time) = '2016-08-01' GROUP BY idUsr HAVING COUNT(*) > 1;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2016-08-29
@frankgalynsky

SELECT id, idUsr, name, time FROM users WHERE DATE(time) BETWEEN '2016-08-01' AND '2016-08-31' GROUP BY idUsr HAVING COUNT(*) > 1

A
Adamos, 2016-08-29
@Adamos

The usual solution is to JOIN the table with itself ON idUsr and date(time) are equal, but the id's are different.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question