Let's say we have this query

```
SELECT * FROM table

```

And this result from it.

```
id | user_id
------------
1  | 1
------------
2  | 1
------------
3  | 2
------------
4  | 1

```

How could I get the count of how often a user\_id appears as another field (without some major SQL query)

```
id | user_id | count
--------------------
1  | 1       | 3
--------------------
2  | 1       | 3
--------------------
3  | 2       | 1
--------------------
4  | 1       | 3

```

We have this value currently in code, but we are implementing sorting to this table and I would like to be able to sort in the SQL query.

BTW if this is not possible without some major trick, we are just going to skip sorting on that field.