

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL query to select rows except first row in descending order?
Let us first create a table −
mysql> create table DemoTable -> ( -> Amount int -> ); Query OK, 0 rows affected (0.50 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(30); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(40); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+--------+ | Amount | +--------+ | 10 | | 20 | | 30 | | 40 | +--------+ 4 rows in set (0.00 sec)
Following is the query to select rows except first row in descending order −
mysql> select *from DemoTable WHERE Amount NOT IN (SELECT MAX(Amount) from DemoTable) ORDER BY Amount DESC;
Output
+--------+ | Amount | +--------+ | 30 | | 20 | | 10 | +--------+ 3 rows in set (0.05 sec)
- Related Questions & Answers
- Select all rows except from today in MySQL?
- MySQL query to first set negative value in descending order and then positive value in ascending order
- MySQL query to select too many rows?
- MySQL query to select multiple rows effectively?
- Delete all rows except only a specific row in MySQL?
- MySQL query to order timestamp in descending order but place the timestamp 0000-00-00 00:00:00 first?
- How to order results of a query randomly & select random rows in MySQL?
- MySQL order by 0 first and then display the record in descending order?
- Select first word in a MySQL query?
- MySQL query to select top n rows efficiently?
- MySQL query to select distinct order by id
- How can I select every alternative row and display in descending order in SQL?
- Select all except the first character in a string in MySQL?
- MySQL query to select one specific row and another random row?
- MySQL query to get a specific row from rows
Advertisements