Podcast
Questions and Answers
What is the main function of the SELECT clause in a SQL statement?
What is the main function of the SELECT clause in a SQL statement?
What is the purpose of the FROM clause in a SQL statement?
What is the purpose of the FROM clause in a SQL statement?
What does the asterisk (*) symbol represent in a SELECT statement?
What does the asterisk (*) symbol represent in a SELECT statement?
What is the keyword used to select only distinct values in a SQL statement?
What is the keyword used to select only distinct values in a SQL statement?
Signup and view all the answers
What is the purpose of using column aliases in a SQL statement?
What is the purpose of using column aliases in a SQL statement?
Signup and view all the answers
Can SQL statements be entered on multiple lines?
Can SQL statements be entered on multiple lines?
Signup and view all the answers
What is the purpose of using a semicolon (;) in SQL statements?
What is the purpose of using a semicolon (;) in SQL statements?
Signup and view all the answers
What is the case sensitivity of SQL statements?
What is the case sensitivity of SQL statements?
Signup and view all the answers
What is the purpose of the concatenation operator in a SELECT statement?
What is the purpose of the concatenation operator in a SELECT statement?
Signup and view all the answers
What is the symbol used to represent the concatenation operator?
What is the symbol used to represent the concatenation operator?
Signup and view all the answers
What happens when a literal character string is included in a SELECT statement?
What happens when a literal character string is included in a SELECT statement?
Signup and view all the answers
What is the purpose of the Alternative Quote (q) Operator?
What is the purpose of the Alternative Quote (q) Operator?
Signup and view all the answers
What is the default display of queries in a SELECT statement?
What is the default display of queries in a SELECT statement?
Signup and view all the answers
What is the purpose of the DISTINCT keyword in a SELECT statement?
What is the purpose of the DISTINCT keyword in a SELECT statement?
Signup and view all the answers
What is the result of combining two character strings using the concatenation operator?
What is the result of combining two character strings using the concatenation operator?
Signup and view all the answers
What is the purpose of enclosing date and character literal values in single quotation marks?
What is the purpose of enclosing date and character literal values in single quotation marks?
Signup and view all the answers
What does a column alias do in a SELECT statement?
What does a column alias do in a SELECT statement?
Signup and view all the answers
What happens when a null value is included in an arithmetic expression?
What happens when a null value is included in an arithmetic expression?
Signup and view all the answers
What is the purpose of the AS keyword in a column alias?
What is the purpose of the AS keyword in a column alias?
Signup and view all the answers
What is the result of the SELECT statement: SELECT last_name, 12salarycommission_pct FROM employees?
What is the result of the SELECT statement: SELECT last_name, 12salarycommission_pct FROM employees?
Signup and view all the answers
What is the purpose of the DESCRIBE command?
What is the purpose of the DESCRIBE command?
Signup and view all the answers
How are column aliases separated from the column name if they contain spaces or special characters?
How are column aliases separated from the column name if they contain spaces or special characters?
Signup and view all the answers
What is the purpose of a basic SELECT statement?
What is the purpose of a basic SELECT statement?
Signup and view all the answers
What is the result of the SELECT statement: SELECT last_name AS name, commission_pct comm FROM employees?
What is the result of the SELECT statement: SELECT last_name AS name, commission_pct comm FROM employees?
Signup and view all the answers
Study Notes
Capabilities of SQL SELECT Statements
- The SQL SELECT statement has three main capabilities: Projection (selecting specific columns), Selection (filtering data), and Join (combining data from multiple tables)
Basic SELECT Statement
- The basic syntax of a SELECT statement is:
SELECT *|{[DISTINCT] column|expression [alias],...} FROM table;
-
SELECT
identifies the columns to be displayed, andFROM
identifies the table containing those columns - The
*
symbol can be used to select all columns
Selecting Columns
- To select specific columns, list them separately in the
SELECT
clause, e.g.,SELECT department_id, location_id FROM departments;
- To select all columns, use
SELECT * FROM table;
Writing SQL Statements
- SQL statements are not case-sensitive
- SQL statements can be entered on one or more lines
- Keywords cannot be abbreviated or split across lines
- Clauses are usually placed on separate lines for readability
- In SQL Developer, SQL statements can be terminated by a semicolon
;
Null Values in Arithmetic Expressions
- Arithmetic expressions containing a null value will evaluate to null
- Example:
SELECT last_name, 12*salary*commission_pct FROM employees;
Column Aliases
- A column alias renames a column heading and is useful with calculations
- A column alias immediately follows the column name, and can be separated by the
AS
keyword - If the alias contains spaces or special characters, it must be enclosed in double quotation marks
Using Column Aliases
- Example:
SELECT last_name AS name, commission_pct comm FROM employees;
- Example:
SELECT last_name "Name" , salary*12 "Annual Salary" FROM employees;
Concatenation Operator
- The concatenation operator
||
links columns or character strings to other columns - It creates a resultant column that is a character expression
- Example:
SELECT last_name||job_id AS "Employees" FROM employees;
Literal Character Strings
- A literal is a character, number, or date that is included in the SELECT statement
- Date and character literal values must be enclosed in single quotation marks
- Each character string is output once for each row returned
Using Literal Character Strings
- Example:
SELECT last_name ||' is a '||job_id AS "Employee Details" FROM employees;
Alternative Quote (q) Operator
- The alternative quote operator allows you to specify your own quotation mark delimiter
- It increases readability and usability
- Example:
SELECT department_name || ' Department' || q'['s Manager Id: ]' || manager_id AS "Department and Manager" FROM departments;
Duplicate Rows
- By default, queries display all rows, including duplicates
- The
DISTINCT
keyword can be used to remove duplicate rows - Example:
SELECT department_id FROM employees;
vsSELECT DISTINCT department_id FROM employees;
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Learn the basics of retrieving data using SQL SELECT statements, including its capabilities, arithmetic expressions, and column aliases. Practice executing basic SELECT statements and more.