I've been looking around for a while, and it seems it cant be found anywhere. I want to know how do you select the 100 highest and the 100 lowst values in a column? The MIN-function only chooses the lowest one and the MAX the highest one.
Anyone out there who knows how you do this?
The MIN() function returns the smallest value of the selected column.
The ORDER BY statement in SQL is used to sort the fetched data in either ascending or descending according to one or more columns. By default ORDER BY sorts the data in ascending order. We can use the keyword DESC to sort the data in descending order and the keyword ASC to sort in ascending order.
So if we see TOP (100) PERCENT in code, we suspect that the developer has attempted to create an ordered view and we check if that's important before going any further. Chances are that the query that uses that view (or the client application) need to be modified instead.
To get the maximum value from three different columns, use the GREATEST() function. Insert some records in the table using insert command. Display all records from the table using select statement.
SQL Server
Top 100 Highest
SELECT TOP 100 * FROM MyTable
ORDER BY MyCol DESC
Top 100 Lowest
SELECT TOP 100 * FROM MyTable
ORDER BY MyCol ASC
MySQL
Top 100 Highest
SELECT * FROM MyTable
ORDER BY MyCol DESC LIMIT 100
Top 100 Lowest
SELECT * FROM MyTable
ORDER BY MyCol ASC LIMIT 100
You can do it as below,
Highest
select * from
tablename
order by
column DESC
limit 0,100
Lowest
select * from
tablename
order by
column ASC
limit 0,100
EDIT
For SQL Server replace select * from
with select TOP 100 * from
The SELECT TOP
clause is used to specify the number of records to return.
Use sorting in ascending and descending order and limit output to 100
if you use Sql server you can order query desc and select top 1000 like :
select top(1000) * from mytable order by value desc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With