I want the top 5 products from a table
If i use this
SELECT MAX(ProductCode) AS ProductName
FROM OrderDetails
I get only one result I want the top 5 result
I want the top 5 products from a table
If i use this
SELECT MAX(ProductCode) AS ProductName
FROM OrderDetails
I get only one result I want the top 5 result
Try this for MySQl
SELECT ProductCode FROM OrderDetails
ORDER BY ProductCode Desc
LIMIT 5
solved..by using this query
SELECT TOP 5 ProductName, COUNT(ProductName) AS value_occurrence FROM OrderDetails GROUP BY ProductName ORDER BY value_occurrence DESC
it depends on what exactly you need top 5 based on .. it can be sorting by what it can be like numbers first and then the characters one ..
as you said it is varchar then please have a look at this question and limit them with how many u need.
How do I sort a VARCHAR column in SQL server that contains numbers?
Hope this helps :)