SELECT LIMIT in MariaDB

MariaDB SELECT LIMIT To fetch limited records from the tables stored in the database, the MariaDB SELECT statement is used with LIMIT clause.

Syntax:

SELECT columns  
FROM table_name
WHERE conditions
ORDER BY expression [ ASC | DESC ] 
LIMIT row_count;   

Parameters: columns: It is used to specify the columns or calculations to be retrieved. table_name: It is used to specify the name of the table from which you want to retrieve the records. conditions: It is used to specify the conditions to be strictly followed for selection. ,strong>row_count: It is used to specify the maximum number of rows to display.

Example 1: Limit in Ascending Order. Students table:

ID	NAME	AGE
1	Joy	5
2	Smiley	13
3	Happy	11
SELECT name, age  
FROM students  
WHERE  age > 10  
ORDER BY name ASC
LIMIT 1;

Output:

ID	NAME	AGE
3	Happy	11

Example 2: Limit in Descending Order.

ID	NAME	AGE
1	Joy	5
2	Smiley	13
3	Happy	11
SELECT name, age  
FROM students  
WHERE  age > 10  
ORDER BY name DESC
LIMIT 1;

Output:

ID	NAME	AGE
2	Smiley	13

Please follow and like us:
Content Protection by DMCA.com