MySQL query to get a specific row from rows


Let us first create a table −

mysql> create table DemoTable1972
   (
   Section char(1),
   StudentName varchar(20)
   );
Query OK, 0 rows affected (0.00 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1972 values('D','Chris');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1972 values('B','David');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1972 values('A','Mike');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1972 values('C','Carol');
Query OK, 1 row affected (0.00 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1972;

This will produce the following output −

+---------+-------------+
| Section | StudentName |
+---------+-------------+
| D       | Chris       |
| B       | David       |
| A       | Mike        |
| C       | Carol       |
+---------+-------------+
4 rows in set (0.00 sec)

Here is the query to get a specific rows from rows −

mysql> select * from DemoTable1972 where Section > 'C' order by Section limit 2;

This will produce the following output −

+---------+-------------+
| Section | StudentName |
+---------+-------------+
| D       | Chris       |
+---------+-------------+
1 row in set (0.00 sec)

Updated on: 31-Dec-2019

316 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements