Please help me with Query in Mysql.. i am Having table contains lot of rows .now i want retrive the 5 rows from that table.
my requirement is top maximum 5 values in that table "column name is amount" i want select from that table.outof N records i need top max 5 records from table
Thanking you,
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.
2nd highest value in SQL using Max() function SELECT MAX (ProductID) FROM Production. WorkOrder WHERE ProductID NOT IN (SELECT MAX (ProductID) FROM Production. WorkOrder);
How do you get max for each group in SQL? To find the maximum value of a column, use the MAX() aggregate function; it takes a column name or an expression to find the maximum value. In our example, the subquery returns the highest number in the column grade (subquery: SELECT MAX(grade) FROM student ).
Just order the rows by (descending) amount and take the top 5:
SELECT amount FROM mytable ORDER BY amount DESC LIMIT 5
Note that this will result in a full table scan unless you have an index on the amount
column. This could affect performance if the number of rows in the table is very large (i.e. many thousands).
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