#
#
#yamynginx2020-03-04 21:02:06
SQL
#yamynginx, 2020-03-04 21:02:06

How to group a selection?

Hello.
I have a likes table, in it:
`id` - just to be.
`user_id` - the person who liked it.
`peer_id` is the person `user_id` likes.

`user_id` can like `peer_id` at least 1000 times, and so I would like to do this: And so that user_id is not duplicated, but written once. But I don't understand how to do it with GROUP BY, any help would be very much appreciated.
SELECT * FROM `users` WHERE `peer_id`=1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Samsonov, 2020-03-04
@muxui

SELECT `user_id`, COUNT(`peer_id`) FROM `users` WHERE `peer_id`=1 GROUP BY `user_id`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question