0% found this document useful (0 votes)
51 views24 pages

Lession 01

This document covers basic SQL statements and concepts. It discusses SELECT statements to retrieve data from tables, arithmetic expressions, NULL values, column aliases, concatenation operators, and using the DISTINCT keyword to eliminate duplicate rows. The key topics covered are writing SELECT statements to return all or specific columns from a table, using operators for calculations, and modifying output with aliases, concatenation, and DISTINCT.

Uploaded by

chandumistry
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views24 pages

Lession 01

This document covers basic SQL statements and concepts. It discusses SELECT statements to retrieve data from tables, arithmetic expressions, NULL values, column aliases, concatenation operators, and using the DISTINCT keyword to eliminate duplicate rows. The key topics covered are writing SELECT statements to return all or specific columns from a table, using operators for calculations, and modifying output with aliases, concatenation, and DISTINCT.

Uploaded by

chandumistry
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 24

BASIC

SQL STATEMENTS

OBJECTIVES
After completing this lesson, you should be able to
do the following:
Execute a basic SELECT statement
Using Arithmetic Expressions
NULL Value Definition
Column Alias
Concatenation Operator
Distinct Keyword

SQL STATEMENTS
SQL statements are not case sensitive.
SQL statements can be on one or more lines.
Keywords cannot be abbreviated or split across lines.
Clauses are usually placed on separate lines.

BASIC SELECT STATEMENT


SELECT
SELECTcolumn_name,
column_name,column_name
column_name
FROM
FROMtable_name;
table_name;
SELECT identifies what columns
FROM identifies which table

SELECTING ALL COLUMNS


SELECT *
FROM
departments;

SELECTING SPECIFIC COLUMNS


SELECT department_id, location_id
FROM
departments;

ARITHMETIC EXPRESSIONS
Create expressions with number and date data by using arithmetic
operators.
Operator

Description

Add

Subtract

Multiply

Divide

USING ARITHMETIC OPERATORS


SELECT first_name, salary, salary * 12
FROM
employees;

OPERATOR PRECEDENCE

* / +

Multiplication and division take priority over addition and


subtraction.
Operators of the same priority are evaluated from left to right.
Parentheses are used to force prioritized evaluation and to clarify
statements.

OPERATOR PRECEDENCE
SELECT last_name, salary, 12*salary+100
FROM
employees;

USING PARENTHESES
SELECT last_name, salary, 12*(salary+100)
FROM employees;

DEFINING A NULL VALUE


A null is a value that is unavailable, unassigned, unknown, or
inapplicable.
A null is not the same as zero or a blank space.
SELECT last_name, job_id, salary, commission_pct
FROM
employees;

NULL VALUES
IN ARITHMETIC EXPRESSIONS
Arithmetic expressions containing a null value evaluate to null.
SELECT last_name, 12*salary*commission_pct
FROM
employees;

DEFINING A COLUMN ALIAS


A column alias:
Renames a column heading
Is useful with calculations
Immediately follows the column name - there can also be the
optional as keyword between the column name and alias
Requires double quotation marks if it contains spaces or special
characters or is case sensitive

USING COLUMN ALIASES


SELECT last_name AS name, commission_pct comm
FROM
employees;

SELECT last_name "Name", salary*12 "Annual Salary"


FROM
employees;

CONCATENATION OPERATOR
A concatenation operator:
Concatenates columns or character strings to other columns
Is represented by two vertical bars (||)
Creates a resultant column that is a character expression

USING THE CONCATENATION


OPERATOR
SELECT
FROM

last_name||job_id AS "Employees"
employees;

LITERAL CHARACTER STRINGS


A literal is a character, a number, or a date included in the select list.
Date and character literal values must be enclosed within single
quotation marks.
Each character string is output once for each
row returned.

USING LITERAL CHARACTER STRINGS


SELECT last_name ||' is a '||job_id
AS "Employee Details"
FROM
employees;

DUPLICATE ROWS
The default display of queries is all rows, including duplicate rows.
SELECT
SELECT
FROM
FROM

department_id
department_id
employees;
employees;

ELIMINATING DUPLICATE ROWS


Eliminate duplicate rows by using the distinct keyword in the select
clause.
SELECT DISTINCT department_id
FROM
employees;

DISPLAYING TABLE STRUCTURE


Use the SQL DESC command to display the structure of a table.

DESC
DESC tablename
tablename

DISPLAYING TABLE STRUCTURE


DESC
DESC employees
employees

SUMMARY
In this lesson, you should have learned how to:

Write a select statement that:

returns all rows and columns from a table

returns specified columns from a table

uses column aliases to give descriptive column headings

You might also like