Order By and Limit Flashcards

1
Q

What is the purpose of the ORDER BY clause?

A

To sort the result-set of a SELECT statement in either ascending or descending order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the default sorting order in the ORDER BY clause?

A

ASC (ascending order).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the DESC keyword do in the ORDER BY clause?

A

Sorts the result-set in descending order (from highest to lowest).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the syntax for the ORDER BY clause?

A

SELECT column1, column2, … FROM table_name ORDER BY column1, column2, … ASC | DESC;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Fill in the blank: The LIMIT clause is used to _______ the number of rows returned by a SELECT statement.

A

[limit]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the offset in the LIMIT clause specify?

A

The starting position of the rows to be returned.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the default value of the offset in the LIMIT clause?

A

0.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the syntax for the LIMIT clause?

A

SELECT column1, column2, … FROM table_name LIMIT [offset,] count;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the count in the LIMIT clause specify?

A

The number of rows to be returned.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What happens when you combine the ORDER BY and LIMIT clauses?

A

You can sort the result-set and then limit the number of rows returned.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Provide an example of a query that uses both ORDER BY and LIMIT clauses.

A

SELECT * FROM customers ORDER BY customer_name ASC LIMIT 5;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Where must the ORDER BY clause be placed in relation to the WHERE clause?

A

After the WHERE clause (if present) and before the LIMIT clause.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How can the LIMIT clause improve the performance of queries?

A

By reducing the amount of data that needs to be processed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is pagination in the context of SQL queries?

A

The process of dividing a large set of data into smaller pages.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

True or False: The ORDER BY clause can be used without the LIMIT clause.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly