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)