
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 Articles
- MySQL query to first set negative value in descending order and then positive value in ascending order
- Select all rows except from today in MySQL?
- How to order results of a query randomly & select random rows in MySQL?
- MySQL query to order timestamp in descending order but place the timestamp 0000-00-00 00:00:00 first?
- Delete all rows except only a specific row in MySQL?
- MySQL query to select too many rows?
- MySQL query to select multiple rows effectively?
- MySQL query to select top n rows efficiently?
- How can I select every alternative row and display in descending order in SQL?
- MySQL query to select distinct order by id
- MySQL order by 0 first and then display the record in descending order?
- Select first word in a MySQL query?
- MySQL query to get a specific row from rows
- Select all except the first character in a string in MySQL?
- MySQL query to generate row index (rank) in SELECT statement?

Advertisements