
- 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
Order MySQL results without identifier?
To order MySQL results without identifier, the syntax is as follows −
select * from yourTableName order by 1 DESC LIMIT yourLimitValue;
Let us first create a table −
mysql> create table DemoTable1325 -> ( -> Id int, -> Name varchar(20) -> ); Query OK, 0 rows affected (0.69 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1325 values(100,'Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1325 values(101,'Bob'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1325 values(120,'David'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1325 values(115,'Sam'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1325 values(130,'Carol'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1325 values(150,'Mike'); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1325;
This will produce the following output −
+------+-------+ | Id | Name | +------+-------+ | 100 | Chris | | 101 | Bob | | 120 | David | | 115 | Sam | | 130 | Carol | | 150 | Mike | +------+-------+ 6 rows in set (0.00 sec)
Here is the query to order MySQL results without identifier −
mysql> select * from DemoTable1325 order by 1 DESC LIMIT 4;
This will produce the following output
+------+-------+ | Id | Name | +------+-------+ | 150 | Mike | | 130 | Carol | | 120 | David | | 115 | Sam | +------+-------+ 4 rows in set (0.00 sec)
- Related Articles
- Execute MySQL query from the terminal without printing results?
- MySQL command to order timestamp values in ascending order without using TIMESTAMP()?
- Implement MySQL ORDER BY without using ASC or DESC?
- Get a fixed number of results in descending order using a MySQL query
- How to order results of a query randomly & select random rows in MySQL?
- Can we return query results in same order as the values in MySQL `IN(…)` statement?
- How to merge MySQL results?
- Organizationally Unique Identifier
- JavaScript this Identifier
- How can we use the MySQL reserved words as an identifier?
- How does COALESCE order results with NULL and NON-NULL values?
- How to order the results of related models in Laravel Eloquent?
- What is the maximum length of each type of identifier in MySQL?
- Display MySQL Results as comma separated list?
- Combine SELECT & SHOW command results in MySQL?

Advertisements