Order By and Limit Flashcards
What is the purpose of the ORDER BY clause?
To sort the result-set of a SELECT statement in either ascending or descending order.
What is the default sorting order in the ORDER BY clause?
ASC (ascending order).
What does the DESC keyword do in the ORDER BY clause?
Sorts the result-set in descending order (from highest to lowest).
What is the syntax for the ORDER BY clause?
SELECT column1, column2, … FROM table_name ORDER BY column1, column2, … ASC | DESC;
Fill in the blank: The LIMIT clause is used to _______ the number of rows returned by a SELECT statement.
[limit]
What does the offset in the LIMIT clause specify?
The starting position of the rows to be returned.
What is the default value of the offset in the LIMIT clause?
0.
What is the syntax for the LIMIT clause?
SELECT column1, column2, … FROM table_name LIMIT [offset,] count;
What does the count in the LIMIT clause specify?
The number of rows to be returned.
What happens when you combine the ORDER BY and LIMIT clauses?
You can sort the result-set and then limit the number of rows returned.
Provide an example of a query that uses both ORDER BY and LIMIT clauses.
SELECT * FROM customers ORDER BY customer_name ASC LIMIT 5;
Where must the ORDER BY clause be placed in relation to the WHERE clause?
After the WHERE clause (if present) and before the LIMIT clause.
How can the LIMIT clause improve the performance of queries?
By reducing the amount of data that needs to be processed.
What is pagination in the context of SQL queries?
The process of dividing a large set of data into smaller pages.
True or False: The ORDER BY clause can be used without the LIMIT clause.
True.