1

Is it possible to check a table for repeated values and if so then will return a result? Lets say we have the following table:

table: views
------------------
id | user | book |
------------------
1  |  1   | b01  |
2  |  1   | b02  |
3  |  2   | b04  |
4  |  2   | b09  |
5  |  2   | b09  |
6  |  2   | b09  |
7  |  2   | b09  |
8  |  3   | b03  |
9  |  3   | b06  |
10 |  3   | b07  |
...

So ...

What I want to print is this part:
------------------
 id | user | book |
------------------
 4  |  2   | b09  |
 5  |  2   | b09  |
 6  |  2   | b09  |
 7  |  2   | b09  |

In plain words we would say that user 2 has repeadet read book no: b09 for 4 times.

Can this be done? Thank you in advance.

0

1 Answer 1

4

Use GROUP BY to get what you want:

SELECT user, book, COUNT(*) as cnt FROM views GROUP BY user, book HAVING cnt > 1

Not the answer you're looking for? Browse other questions tagged or ask your own question.