The LIMIT clause is used in the SELECT statement to constrain the number of rows to return. The LIMIT clause accepts one or two arguments. The values of both arguments must be zero or positive integers.
Setting environment for using XAMPP for Windows.
Mounika@MOUNIKA-PC c:\xampp
# ram.cmd
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.4.18-MariaDB mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use vlrinst;
Database changed
MariaDB [vlrinst]> select * from emp;
+----+---------+-----------+------+-------+
| id | name | loc | age | sal |
+----+---------+-----------+------+-------+
| 10 | venkat | kphb | 35 | 30000 |
| 11 | praveen | pune | 28 | 35000 |
| 12 | mounika | hyderabad | 22 | 39000 |
| 13 | revathi | jntu | 26 | 20000 |
| 14 | anji | gutta | 28 | 20000 |
| 15 | harika | lb nagar | 26 | 30100 |
| 16 | praveen | jntu | 33 | 100 |
| 17 | pandu | munipeda | 35 | 30300 |
| 18 | pandu | pune | 23 | 39300 |
+----+---------+-----------+------+-------+
9 rows in set (0.001 sec)
MariaDB [vlrinst]> select * from emp limit 1;
+----+--------+------+------+-------+
| id | name | loc | age | sal |
+----+--------+------+------+-------+
| 10 | venkat | kphb | 35 | 30000 |
+----+--------+------+------+-------+
1 row in set (0.001 sec)
MariaDB [vlrinst]> select * from emp limit 5;
+----+---------+-----------+------+-------+
| id | name | loc | age | sal |
+----+---------+-----------+------+-------+
| 10 | venkat | kphb | 35 | 30000 |
| 11 | praveen | pune | 28 | 35000 |
| 12 | mounika | hyderabad | 22 | 39000 |
| 13 | revathi | jntu | 26 | 20000 |
| 14 | anji | gutta | 28 | 20000 |
+----+---------+-----------+------+-------+
5 rows in set (0.001 sec)
MariaDB [vlrinst]> select * from emp limit 5,10;
+----+---------+----------+------+-------+
| id | name | loc | age | sal |
+----+---------+----------+------+-------+
| 15 | harika | lb nagar | 26 | 30100 |
| 16 | praveen | jntu | 33 | 100 |
| 17 | pandu | munipeda | 35 | 30300 |
| 18 | pandu | pune | 23 | 39300 |
+----+---------+----------+------+-------+
4 rows in set (0.040 sec)
MariaDB [vlrinst]> select * from emp limit 3,7;
+----+---------+----------+------+-------+
| id | name | loc | age | sal |
+----+---------+----------+------+-------+
| 13 | revathi | jntu | 26 | 20000 |
| 14 | anji | gutta | 28 | 20000 |
| 15 | harika | lb nagar | 26 | 30100 |
| 16 | praveen | jntu | 33 | 100 |
| 17 | pandu | munipeda | 35 | 30300 |
| 18 | pandu | pune | 23 | 39300 |
+----+---------+----------+------+-------+
6 rows in set (0.001 sec)
MariaDB [vlrinst]> select * from emp limit 3,2;
+----+---------+-------+------+-------+
| id | name | loc | age | sal |
+----+---------+-------+------+-------+
| 13 | revathi | jntu | 26 | 20000 |
| 14 | anji | gutta | 28 | 20000 |
+----+---------+-------+------+-------+
2 rows in set (0.001 sec)
MariaDB [vlrinst]> select * from emp limit 3,3;
+----+---------+----------+------+-------+
| id | name | loc | age | sal |
+----+---------+----------+------+-------+
| 13 | revathi | jntu | 26 | 20000 |
| 14 | anji | gutta | 28 | 20000 |
| 15 | harika | lb nagar | 26 | 30100 |
+----+---------+----------+------+-------+
3 rows in set (0.001 sec)
MariaDB [vlrinst]> select * from emp limit 1,7;
+----+---------+-----------+------+-------+
| id | name | loc | age | sal |
+----+---------+-----------+------+-------+
| 11 | praveen | pune | 28 | 35000 |
| 12 | mounika | hyderabad | 22 | 39000 |
| 13 | revathi | jntu | 26 | 20000 |
| 14 | anji | gutta | 28 | 20000 |
| 15 | harika | lb nagar | 26 | 30100 |
| 16 | praveen | jntu | 33 | 100 |
| 17 | pandu | munipeda | 35 | 30300 |
+----+---------+-----------+------+-------+
7 rows in set (0.000 sec)
MariaDB [vlrinst]> select * from emp limit 1,4;
+----+---------+-----------+------+-------+
| id | name | loc | age | sal |
+----+---------+-----------+------+-------+
| 11 | praveen | pune | 28 | 35000 |
| 12 | mounika | hyderabad | 22 | 39000 |
| 13 | revathi | jntu | 26 | 20000 |
| 14 | anji | gutta | 28 | 20000 |
+----+---------+-----------+------+-------+
4 rows in set (0.001 sec)
MariaDB [vlrinst]> select * from emp limit 4;
+----+---------+-----------+------+-------+
| id | name | loc | age | sal |
+----+---------+-----------+------+-------+
| 10 | venkat | kphb | 35 | 30000 |
| 11 | praveen | pune | 28 | 35000 |
| 12 | mounika | hyderabad | 22 | 39000 |
| 13 | revathi | jntu | 26 | 20000 |
+----+---------+-----------+------+-------+
4 rows in set (0.001 sec)
MariaDB [vlrinst]> select * from emp limit 3,4;
+----+---------+----------+------+-------+
| id | name | loc | age | sal |
+----+---------+----------+------+-------+
| 13 | revathi | jntu | 26 | 20000 |
| 14 | anji | gutta | 28 | 20000 |
| 15 | harika | lb nagar | 26 | 30100 |
| 16 | praveen | jntu | 33 | 100 |
+----+---------+----------+------+-------+
4 rows in set (0.001 sec)
MariaDB [vlrinst]> select * from emp where loc="jntu";
+----+---------+------+------+-------+
| id | name | loc | age | sal |
+----+---------+------+------+-------+
| 13 | revathi | jntu | 26 | 20000 |
| 16 | praveen | jntu | 33 | 100 |
+----+---------+------+------+-------+
2 rows in set (0.048 sec)
MariaDB [vlrinst]> select * from emp where loc="jntu" limit 1;
+----+---------+------+------+-------+
| id | name | loc | age | sal |
+----+---------+------+------+-------+
| 13 | revathi | jntu | 26 | 20000 |
+----+---------+------+------+-------+
1 row in set (0.002 sec)
MariaDB [vlrinst]> select * from emp order by sal;
+----+---------+-----------+------+-------+
| id | name | loc | age | sal |
+----+---------+-----------+------+-------+
| 16 | praveen | jntu | 33 | 100 |
| 13 | revathi | jntu | 26 | 20000 |
| 14 | anji | gutta | 28 | 20000 |
| 10 | venkat | kphb | 35 | 30000 |
| 15 | harika | lb nagar | 26 | 30100 |
| 17 | pandu | munipeda | 35 | 30300 |
| 11 | praveen | pune | 28 | 35000 |
| 12 | mounika | hyderabad | 22 | 39000 |
| 18 | pandu | pune | 23 | 39300 |
+----+---------+-----------+------+-------+
9 rows in set (0.001 sec)
MariaDB [vlrinst]> select * from emp order by sal desc;
+----+---------+-----------+------+-------+
| id | name | loc | age | sal |
+----+---------+-----------+------+-------+
| 18 | pandu | pune | 23 | 39300 |
| 12 | mounika | hyderabad | 22 | 39000 |
| 11 | praveen | pune | 28 | 35000 |
| 17 | pandu | munipeda | 35 | 30300 |
| 15 | harika | lb nagar | 26 | 30100 |
| 10 | venkat | kphb | 35 | 30000 |
| 13 | revathi | jntu | 26 | 20000 |
| 14 | anji | gutta | 28 | 20000 |
| 16 | praveen | jntu | 33 | 100 |
+----+---------+-----------+------+-------+
9 rows in set (0.001 sec)
MariaDB [vlrinst]> select * from emp order by sal desc limit 1;
+----+-------+------+------+-------+
| id | name | loc | age | sal |
+----+-------+------+------+-------+
| 18 | pandu | pune | 23 | 39300 |
+----+-------+------+------+-------+
1 row in set (0.001 sec)
MariaDB [vlrinst]> select * from emp order by sal desc limit 3;
+----+---------+-----------+------+-------+
| id | name | loc | age | sal |
+----+---------+-----------+------+-------+
| 18 | pandu | pune | 23 | 39300 |
| 12 | mounika | hyderabad | 22 | 39000 |
| 11 | praveen | pune | 28 | 35000 |
+----+---------+-----------+------+-------+
3 rows in set (0.001 sec)
MariaDB [vlrinst]> select * from emp where loc="jntu";
+----+---------+------+------+-------+
| id | name | loc | age | sal |
+----+---------+------+------+-------+
| 13 | revathi | jntu | 26 | 20000 |
| 16 | praveen | jntu | 33 | 100 |
+----+---------+------+------+-------+
2 rows in set (0.001 sec)
MariaDB [vlrinst]> select * from emp where loc="jntu" order by sal;
+----+---------+------+------+-------+
| id | name | loc | age | sal |
+----+---------+------+------+-------+
| 16 | praveen | jntu | 33 | 100 |
| 13 | revathi | jntu | 26 | 20000 |
+----+---------+------+------+-------+
2 rows in set (0.001 sec)
MariaDB [vlrinst]> select * from emp where loc="jntu" order by sal limit 1;
+----+---------+------+------+------+
| id | name | loc | age | sal |
+----+---------+------+------+------+
| 16 | praveen | jntu | 33 | 100 |
+----+---------+------+------+------+
1 row in set (0.001 sec)
MariaDB [vlrinst]> select name from emp where loc="jntu" order by sal limit 1;
+---------+
| name |
+---------+
| praveen |
+---------+
1 row in set (0.001 sec)
MariaDB [vlrinst]> select name,sal from emp where loc="jntu" order by sal limit 1;
+---------+------+
| name | sal |
+---------+------+
| praveen | 100 |
+---------+------+
1 row in set (0.001 sec)
MariaDB [vlrinst]>
No comments:
Post a Comment
Note: only a member of this blog may post a comment.