

- 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
Display first selected row in MySQL?
You can use ORDER BY for this. Let us first create a table −
mysql> create table DemoTable ( Value int ); Query OK, 0 rows affected (0.20 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values(8); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(18); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values(11); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(9); Query OK, 1 row affected (0.05 sec) mysql> insert into DemoTable values(19); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values(6); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(7); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------+ | Value | +-------+ | 20 | | 8 | | 18 | | 11 | | 9 | | 19 | | 6 | | 7 | +-------+ 8 rows in set (0.00 sec)
Following is the query to display first selected row in MySQL −
mysql> select *from DemoTable order by (Value=9) DESC,Value DESC;
This will produce the following output −
+-------+ | Value | +-------+ | 9 | | 20 | | 19 | | 18 | | 11 | | 8 | | 7 | | 6 | +-------+ 8 rows in set (0.00 sec)
- Related Questions & Answers
- Display multiple selected rows using MySQL IN()
- MySQL limit in a range fail to display first 3 row?
- Display selected records from a MySQL table with IN() operator
- Display random row from a MySQL table
- Implement MySQL IN for 2 columns to display only selected records
- Only display row with highest ID in MySQL
- Display sum in last row of table using MySQL?
- Display first non-null values with coalesce() in MySQL?
- MySQL query to select rows except first row in descending order?
- Order by selected record in MySQL?
- Highest occurrence in an array or first selected in JavaScript
- Get the first 10 rows followed by the syntax to display remaining row records with a single MySQL query
- How to select first and last row record using LIMIT in MySQL?
- Display records by first fixing the first two values in a column and then using DISTINCT to display other values in MySQL
- Query non-empty values of a row first in ascending order and then display NULL values
Advertisements