A Guide to SQL
A Guide to SQL
9th Edition
ISBN: 9781111527273
Author: Philip J. Pratt
Publisher: Course Technology Ptr
bartleby

Concept explainers

Question
Book Icon
Chapter 4, Problem 10RQ
Program Plan Intro

“ORDER BY” Clause:

  • User can sort the data in specific order using “ORDER BY” clause.
  • The column on which to sort data is called a sort key or a simple key.
  • To sort the output, use an “ORDER BY” clause followed by the sort key.
  • If the user does not specify a sort order, the output displayed in default order that is ascending order.

Example:

The example for “ORDER BY” clause is given below:

SELECT STUDENT_ID, STUDENT_NAME, STUDENT_CREDIT FROM STUDENT ORDER BY STUDENT_CREDIT;

Explanation:

The above query is used to list student ID, name and credit for each student with ascending order of student credit using an “ORDER BY” clause.

  • From the given query, the sort key is “STUDENT_CREDIT”. So, the rows are sorted in ascending order by “STUDENT_CREDIT”.

Explanation of Solution

Most important key:

  • The more important column is called the most important key.
  • It is also called as the major sort key or the primary sort key.

Example:

The example for most important key is given below:

SELECT STUDENT_ID, STUDENT_NAME, STUDENT_CREDIT FROM STUDENT ORDER B...

Explanation of Solution

Less important key:

  • The less important column is called the most important key.
  • It is also called as the minor sort key or the secondary sort key.

Example:

The example for less important key is given below:

SELECT STUDENT_ID, STUDENT_NAME, STUDENT_CREDIT FROM STUDENT ORDER...

Blurred answer
Students have asked these similar questions
Why it's useful to have index that partially sort a query if it doesn't present all of the results already sorted?
Most of the time, tables and data ranges are sorted in ascending sequence. When would you want to sort in descending sequence? When would the order not matter? Would it always matter?
List the trip name, trip id and customer number of all reservations for hiking trips. Sort the results in ascending order by trip id as the major sort key and customer number as the minor sort key

Chapter 4 Solutions

A Guide to SQL

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
  • Text book image
    A Guide to SQL
    Computer Science
    ISBN:9781111527273
    Author:Philip J. Pratt
    Publisher:Course Technology Ptr
    Text book image
    Np Ms Office 365/Excel 2016 I Ntermed
    Computer Science
    ISBN:9781337508841
    Author:Carey
    Publisher:Cengage
    Text book image
    Oracle 12c: SQL
    Computer Science
    ISBN:9781305251038
    Author:Joan Casteel
    Publisher:Cengage Learning
  • Text book image
    CMPTR
    Computer Science
    ISBN:9781337681872
    Author:PINARD
    Publisher:Cengage
Text book image
A Guide to SQL
Computer Science
ISBN:9781111527273
Author:Philip J. Pratt
Publisher:Course Technology Ptr
Text book image
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
Text book image
Oracle 12c: SQL
Computer Science
ISBN:9781305251038
Author:Joan Casteel
Publisher:Cengage Learning
Text book image
CMPTR
Computer Science
ISBN:9781337681872
Author:PINARD
Publisher:Cengage