** LIMIT** is used to display a certain number of rows from the table.

`SELECT column FROM table LIMIT n;`

n = Number of rows

**Database**: *jai_school***Table**: *students*

**Rows**:

s_n | name | class | roll_no | due_fee |
---|---|---|---|---|

1 | Ram | 8 | 1 | 8000 |

2 | Rahim | 8 | 2 | 16000 |

3 | Shyam | 8 | 3 | 7000 |

4 | Anita | 8 | 4 | 9000 |

5 | Jai | 8 | 5 | 7000 |

6 | Ravina | 6 | 1 | 13000 |

7 | Aman | 6 | 2 | 3000 |

**Show the first 4 rows**

`SELECT * FROM students LIMIT 4;`

Output:

LIMIT has 2 parameters if we want to see rows starting from 10 to 20 then we will write query LIMIT 9,19 because rows indexing number starts from 0.

LIMIT 0,12 means from starting row (indexing number 0) to the next 12 rows (after the row having 0 indexing number).

LIMIT 40,10 means the row having indexing number 40 (39th row) to the next 10 rows after indexing number 40.

**Show the last 4 rows**

`SELECT * FROM students ORDER BY s_n DESC LIMIT 4;`

Output:

**LIMIT with WHERE**

`SELECT * FROM students WHERE class="8" LIMIT 3;`

Output:

**LIMIT with WHERE & ORDER BY**

`SELECT * FROM students WHERE class="8" ORDER BY s_n DESC LIMIT 3;`

Output:

## Publish A Comment