How to find lowest count of rows for a value in SQL Server 2005

Sourav Sarkar

I have a table OrderUser

UserName   |  OrderNo
-----------------------
User1      |  1
User1      |  2
User1      |  3
User2      |  4
User2      |  5

I need the only the userID with min rows, meaning user2 in this case.

Simple T-Sql statement is required because I will use the code in a SqlCommand in C#.

Please help.

Menno
SELECT TOP 1 UserName, COUNT(*) 
FROM myTable 
GROUP BY UserName 
ORDER BY COUNT(*) ASC

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to find the lowest value and the corresponding date SQL-Server 2014

From Dev

how do i find multiple count of value for rows in sql?

From Dev

Key Value Pair XML (SQL Server 2005)

From Dev

SQL Server 2005 : If statement with return value

From Dev

Update based on previous value SQL SERVER 2005

From Dev

Change Increment value for Identity - SQL Server 2005

From Dev

SQL Server 2005 - Insert with Select for 1 Value

From Dev

How to find a postion of the lowest value in the file?

From Dev

How to find the lowest value out of a set of variables

From Dev

Using datediff to find the lowest value with a given gap between rows

From Dev

How to set rows value as column in SQL Server?

From Dev

SQL server count another rows

From Dev

How to find exact time of last received transaction on asynchronous mirror (SQL Server 2005)?

From Dev

how to store the Kannada in SQL Server 2005

From Dev

How to rename a column in SQL Server 2005

From Dev

SQL Server 2005 GROUP BY and COUNT query for each month

From Dev

Convert from ACCESS TRANSFORM COUNT/PIVOT to SQL SERVER 2005

From Dev

SQL Server 2005 GROUP BY and COUNT query for each month

From Dev

Compare multiple rows from the same table in SQL Server 2005

From Dev

Concat columns in different rows with same ID SQL Server 2005

From Dev

Get median value of a time period in SQL Server 2005, 2008 server

From Dev

Encryption SQL Server 2005

From Dev

how to select rows that contains non-english characters in sql server 2005(it should filter only non-english chars, not special characters)

From Dev

How find size of selected rows in a table of Sql server?

From Dev

sql server - how do i find rows with whitespace in a column

From Dev

SQL Server Join Confusion - How to Find Missing Rows

From Dev

How find size of selected rows in a table of Sql server?

From Dev

SQL Server: select count of rows with not empty fields and total count of rows

From Dev

How to count rows with specific value?

Related Related

  1. 1

    How to find the lowest value and the corresponding date SQL-Server 2014

  2. 2

    how do i find multiple count of value for rows in sql?

  3. 3

    Key Value Pair XML (SQL Server 2005)

  4. 4

    SQL Server 2005 : If statement with return value

  5. 5

    Update based on previous value SQL SERVER 2005

  6. 6

    Change Increment value for Identity - SQL Server 2005

  7. 7

    SQL Server 2005 - Insert with Select for 1 Value

  8. 8

    How to find a postion of the lowest value in the file?

  9. 9

    How to find the lowest value out of a set of variables

  10. 10

    Using datediff to find the lowest value with a given gap between rows

  11. 11

    How to set rows value as column in SQL Server?

  12. 12

    SQL server count another rows

  13. 13

    How to find exact time of last received transaction on asynchronous mirror (SQL Server 2005)?

  14. 14

    how to store the Kannada in SQL Server 2005

  15. 15

    How to rename a column in SQL Server 2005

  16. 16

    SQL Server 2005 GROUP BY and COUNT query for each month

  17. 17

    Convert from ACCESS TRANSFORM COUNT/PIVOT to SQL SERVER 2005

  18. 18

    SQL Server 2005 GROUP BY and COUNT query for each month

  19. 19

    Compare multiple rows from the same table in SQL Server 2005

  20. 20

    Concat columns in different rows with same ID SQL Server 2005

  21. 21

    Get median value of a time period in SQL Server 2005, 2008 server

  22. 22

    Encryption SQL Server 2005

  23. 23

    how to select rows that contains non-english characters in sql server 2005(it should filter only non-english chars, not special characters)

  24. 24

    How find size of selected rows in a table of Sql server?

  25. 25

    sql server - how do i find rows with whitespace in a column

  26. 26

    SQL Server Join Confusion - How to Find Missing Rows

  27. 27

    How find size of selected rows in a table of Sql server?

  28. 28

    SQL Server: select count of rows with not empty fields and total count of rows

  29. 29

    How to count rows with specific value?

HotTag

Archive