
- 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
Can we select second largest record from a table without using LIMIT clause in MySQL?
Yes, we can select second largest record from a table without using LIMIT clause. Let us first see an example and create a table −
mysql> create table DemoTable ( Number int ); Query OK, 0 rows affected (0.66 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable values(78); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(67); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable values(92); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(98); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(88); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(86); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(89); Query OK, 1 row affected (0.14 sec)
Following is the query to display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------+ | Number | +--------+ | 78 | | 67 | | 92 | | 98 | | 88 | | 86 | | 89 | +--------+ 7 rows in set (0.00 sec)
Following is the query to select second largest number from a table without using LIMIT clause −
mysql> SELECT MAX(Number) FROM DemoTable WHERE Number < (SELECT MAX(Number) FROM DemoTable);
This will produce the following output −
+-------------+ | MAX(Number) | +-------------+ | 92 | +-------------+ 1 row in set (0.00 sec)
- Related Articles
- How can we use MySQL SELECT without FROM clause?
- Get second largest marks from a MySQL table using subquery?
- SELECT last entry without using LIMIT in MySQL?
- Delete a specific record from a MySQL table by using AND in WHERE clause
- How Can we use MySQL DISTINCT clause with WHERE and LIMIT clause?
- Check if table exist without using “select from” in MySQL?
- How to select first and last row record using LIMIT in MySQL?
- How to select record from last 6 months in a news table using MySQL?
- How to get the second last record from a table in MySQL?
- How can you delete a record from a table using MySQL in Python?
- How can we search a record from MySQL table having a date as a value in it?
- Insert record using MySQL SELECT?
- How can we fetch a second highest salary of an employee from a MySQL table?
- How can we use a MySQL subquery with FROM clause?
- Insert values from the first table to the second table using two SELECT statements in a single MySQL query

Advertisements