W3. SQL Order By Flashcards

1
Q

Q: What is the purpose of the SQL ORDER BY keyword?

A

A: To sort the result set in ascending or descending order.

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

Q: Write a SQL query to sort products by price in ascending order.

A
SELECT * FROM Products 
ORDER BY Price;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Q: What is the default order for sorting when using ORDER BY?

A

A: Ascending order.

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

Q: How do you modify ORDER BY to sort results in descending order?

A

A: Add the DESC keyword after the column name.

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

Q: Write a query to sort products from highest to lowest price.

A
SELECT * FROM Products 
ORDER BY Price DESC;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Q: How does ORDER BY sort string values?

A

A: Alphabetically by default.

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

Q: Write a query to sort products alphabetically by ProductName.

A

SELECT * FROM Products
ORDER BY ProductName;

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

Q: How do you sort a column in reverse alphabetical order?

A

A: Use the DESC keyword after the column name.

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

Q: Write a query to sort products by ProductName in reverse alphabetical order.

A
SELECT * FROM Products 
ORDER BY ProductName DESC;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Q: How can you sort by multiple columns in SQL?

A

A: List the columns in ORDER BY, separated by commas.

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

Q: Write a query to sort customers by Country and then by CustomerName.

A

SELECT * FROM Customers
ORDER BY Country, CustomerName;

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

Q: How do you specify different sort orders for multiple columns?

A

A: Use ASC or DESC for each column in the ORDER BY clause.

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

Q: Write a query to sort customers by Country in ascending order and CustomerName in descending order.

A

SELECT * FROM Customers
ORDER BY Country ASC, CustomerName DESC;

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