Get the most common items in List<T> and sort after that
.net, c#, linq, sql
Solution
Use the `GroupBy` extension method provided by LINQ.
// Pseudo code
var grouped = list.GroupBy(item => item.UserID);
You can then call `OrderByDescending` to sort your results:
var sorted = grouped.OrderByDescending(group => group.Count());
Problem
I have a `List<T>` of an object/class which has already been filled with data from a SQL database. What I want to do is to find out who the most common user in this table is and sort the new list based on and starting on the most common user I have no idea how to style a table here on Stackoverflow so you have to bear with me. The database table can for example look like this: ``` id - userID - randomColumn - randomColumn2 1 - 2 - ExampleText - ExampleText 2 - 2 - ExampleText - ExampleText 3 - 1 - ExampleText - ExampleText 4 - 3 - ExampleText - ExampleText 5 - 2 - ExampleText - ExampleText 6 - 1 - ExampleText - ExampleText ``` I want to use either LINQ or SQL to format this so I get a list that looks like this ``` userID - amountColumn - randomColumn 2 - 3 - ExampleText 1 - 2 - ExampleText 3 - 1 - ExampleText ```