![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
Advertisements