VOOZH about

URL: https://www.geeksforgeeks.org/python/python-sqlite-limit-clause/

⇱ Python SQLite - LIMIT Clause - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python SQLite - LIMIT Clause

Last Updated : 27 Apr, 2021

In this article, we are going to discuss the LIMIT clause in SQLite using Python. But first, let's get a brief about the LIMIT clause.

If there are many tuples satisfying the query conditions, it might be resourceful to view only a handful of them at a time. LIMIT keyword is used to limit the data given by the SELECT statement.

Syntax:

         SELECT column1, column2, column n  

         FROM table_name

         LIMIT [no of rows];

where no of rows is an integer value specified as the no of rows to get as output from table.

Let's create a database.

Output:

👁 Image

Now, Insert 5 records into the customer_address table.

Output:

👁 Image

After adding data let's perform the limit operation. In this example, we are going to display the top 4 data from the table.

Output:

👁 Image

In this way, we can restrict the rows in the output and print the top N rows by setting the LIMIT as N.

Comment
Article Tags:
Article Tags: