Section 6 ORDER BY:

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/21

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 5:55 PM on 9/27/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

22 Terms

1
New cards

What does ORDER BY do?

Sorts the final query results by one or more fields.

2
New cards

What types of fields can ORDER BY sort?

Numbers, dates, and text/string fields.

3
New cards

What happens if a query has no ORDER BY clause?

Results are unsorted and usually display in the order recorded in the database.

4
New cards

What is the default ORDER BY sort direction?

Ascending (ASC).

5
New cards

What does ASC mean?

Ascending order: lowest to highest, earliest to latest, or A to Z.

6
New cards

What does DESC mean?

Descending order: highest to lowest, latest to earliest, or Z to A.

7
New cards

Example: sort names A–Z

SELECT Name FROM Customer ORDER BY Name ASC;

8
New cards

Alternative query for names A–Z

SELECT Name FROM Customer ORDER BY Name;

9
New cards

Why do SELECT Name FROM Customer ORDER BY Name; and ORDER BY Name ASC give the same result?

ASC is the default sort order.

10
New cards

Example: sort credit scores highest to lowest

SELECT Name, CreditScore FROM Customer ORDER BY CreditScore DESC;

11
New cards

Example: sort dates oldest to newest

SELECT Name, FirstPurchase FROM Customer ORDER BY FirstPurchase ASC;

12
New cards

Example: sort dates newest to oldest

SELECT Name, FirstPurchase FROM Customer ORDER BY FirstPurchase DESC;

13
New cards

How do you sort by more than one field?

List fields in ORDER BY, separated by commas.

14
New cards

Example: sort first by State, then by Name

SELECT Name, State FROM Customer ORDER BY State ASC, Name ASC;

15
New cards

What does ORDER BY State ASC, Name ASC do?

Sorts states A–Z; within each state, it sorts names A–Z.

16
New cards

What is the most important rule for multiple-field sorting?

The first field is sorted first; the next field breaks ties.

17
New cards

Example: sort by highest credit score, then name A–Z

SELECT Name, CreditScore FROM Customer ORDER BY CreditScore DESC, Name ASC;

18
New cards

Can each ORDER BY field have a different direction?

Yes. Example: ORDER BY State ASC, CreditScore DESC.

19
New cards

Where is ORDER BY written in a basic SELECT query?

After FROM and WHERE. Example: SELECT Name FROM Customer WHERE State = 'Utah' ORDER BY Name ASC;

20
New cards

When does ORDER BY execute?

Near the end—after SELECT and DISTINCT.

21
New cards

Exam tip: What must match the question exactly?

The ORDER BY field order and each field’s sort direction (ASC or DESC).

22
New cards

Exam tip: ASC vs. DESC

ASC = A–Z/low–high/old–new; DESC = Z–A/high–low/new–old.