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 6CAT
Program Plan Intro

“SELECT” command:

The “SELECT” command is used to retrieve data in a database.

Syntax for selecting values from the table is as follows:

SELECT STUDENT_ID FROM STUDENT;

  • The given query is used to display each student ID from “STUDENT” table.

“IN” Clause:

  • The “IN” clause consists of an “IN” operator followed by a set of values.
  • Using an “IN” clause, user can determine whether a column contains one of a particular group of values.

Example:

The example for “IN” clause is given below:

SELECT STUDENT_ID, STUDENT_NAME, STUDENT_CREDIT FROM STUDENT WHERE STUDENT_CREDIT IN(50, 70, 100);

 The above query is used to list student ID, name, and credit for each student with a credit limit of “50”, “70” or “100”.

  • From the given query, user can determine whether a student credit limit is “50”, “70” or “100” using an “IN” operator.

“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 indicate 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;

 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”.

“DESC” Operator:

  • User can sort the data in descending order using a “DESC” operator.
  • To sort in descending order, user follows the name of the sort key with the “DESC” operator.

Example:

The example for “DESC” operator is given below:

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

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

  • From the given query, the sort key is “STUDENT_CREDIT”.

Blurred answer
Students have asked these similar questions
List unique first (first_name) and last names (last_name) of customers (CUSTOMER table) who rented a movie (RENTAL table) between '2011-06-01' and '2012-01-01’ (rental_date). Sort by last_name. The common key is CUSTOMER_ID.
The COUNT(*) function in the SELECT clause is used to return:a. the number of records in the specified tablesb. the number of orders placed by each customerc. the number of NULL values in the specified tablesd. the number of customers who have placed an order
5. Determine the profit of each book sold to Jake Lucas, using the actual price the customerpaid (not the book’s regular retail price). Sort the results by order date. If more than onebook was ordered, sort the results by profit amount in descending order. Perform thesearch using the customer name, not the customer number.

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
SEE MORE 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
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781305627482
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781285196145
Author:Steven, Steven Morris, Carlos Coronel, Carlos, Coronel, Carlos; Morris, Carlos Coronel and Steven Morris, Carlos Coronel; Steven Morris, Steven Morris; Carlos Coronel
Publisher:Cengage Learning
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning