Beruflich Dokumente
Kultur Dokumente
Objectives
Understand
statements
Construct a simple SELECT statement
Using SELECT clause to select field(s) to be
displayed
Understands the usage of arithmetic
operators
Usefulness of column aliases and
concatenation operator
Learn to remove duplicate rows in the result
CS165 Structured Query Language
Projection
Table 1
Table 1
Join
Table 1
Table 2
CS165 Structured Query Language
SELECT identifies
the columns to be
displayed.
FROM identifies the table that contains the
columns.
CS165 Structured Query Language
SELECT clause
The
SELECTING fields
Select All
Fields
SELECT *
FROM course;
Output:
CourseDesp
CourseID
MentorID
DCS
1006
DGAT
1004
DIC
Diploma In Computing
1006
DICT
1002
DIT
1001
DNC
1003
SELECTING fields
Select
SELECT CourseDesp
FROM course;
Output:
CourseDesp
Diploma In Computer Studies
Diploma in Gaming and Animation Techniques
Diploma In Computing
Diploma In Info-Comm Technology
Diploma In Information Technology
Diploma in Network and CyberSecurity
SELECTING fields
Select
GPA
Bartell
3.21
Kebel
2.71
Lee
3.82
Lewis
2.51
Law
3.05
Mikulski
1.89
.
.
Chan
3.12
Jann
Arithmetic Expressions
Create expressions on NUMBER and
DATE data types by using arithmetic
operators.
Operator
Description
Add
Subtract
Multiply
Divide
10
Output:
Lastname
DateEnrolled
Expr1002
Bartell
15-Feb-02
3.26
Kebel
23-Jun-01
2.76
Lee
05-Jan-02
3.87
Lewis
03-Mar-00
2.56
Law
01-Apr-01
3.1
...
CS165 Structured Query Language
11
Operator Precedence
* / +
Multiplication
12
Operator Precedence
SELECT LastName, DateEnrolled, GPA * 4 + 0.05
FROM student;
Output:
LastName
DateEnrolled
Expr1002
Bartell
15-Feb-02
12.89
Kebel
23-Jun-01
10.89
Lee
05-Jan-02
15.33
Lewis
03-Mar-00
10.09
Law
01-Apr-01
12.25
Mikulski
12-Sep-03
7.61
Tham
19-Sep-03
15.61
..
CS165 Structured Query Language
13
Using Parenthesis
SELECT LastName, DateEnrolled, (GPA + 0.05) * 4
FROM student;
Output:
LastName
DateEnrolled
Expr1002
Bartell
15-Feb-02
13.04
Kebel
23-Jun-01
11.04
Lee
05-Jan-02
15.48
Lewis
03-Mar-00
10.24
Law
01-Apr-01
12.4
Mikulski
12-Sep-03
7.76
Tham
19-Sep-03
15.76
14
a column heading
Is useful with calculations
Immediately follows column name; MUST
have AS keyword between column name
and alias
Requires square brackets ( [ ] ) if it is
contains spaces or special characters
The alias case will follow exactly what is
entered.
CS165 Structured Query Language
15
DateEnrolled
NEWGPA
Bartell
15-Feb-02
3.26
Kebel
23-Jun-01
2.76
Lee
05-Jan-02
3.87
Lewis
03-Mar-00
2.56
Law
01-Apr-01
3.1
Mikulski
12-Sep-03
1.94
Tham
19-Sep-03
3.94
16
Family Name
DateEnrolled
New GPA
Bartell
15-Feb-02
3.26
Kebel
23-Jun-01
2.76
Lee
05-Jan-02
3.87
Lewis
03-Mar-00
2.56
Law
01-Apr-01
3.1
Mikulski
12-Sep-03
1.94
Tham
19-Sep-03
3.94
17
Concatenation Operator
Concatenates
18
..
CS165 Structured Query Language
19
Literals
A literal
20
21
Duplicate Rows
SELECT CourseID
FROM student;
Output:
CourseID
DCS
DIC
DIT
DICT
Duplicate
rows
DIT
DCS
DCS
DIC
DICT
DIC
DIT
DICT
DIT
DCS
DIC
DNC
22
23
24
Summary
Select
25