Big Data Analytics: Database - SQL
Big Data Analytics: Database - SQL
1
9/14/2021
2
9/14/2021
Simple Queries
• The purpose of the SELECT statement is to retrieve and display
data from one or more database tables
Simple Queries
• SELECT is the most frequently used SQL command and has the
following general form:
3
9/14/2021
Simple Queries
• The sequence of processing in a SELECT statement is:
• FROM: specifies the table or tables to be used
• WHERE: filters the rows subject to some condition
• GROUP: BY forms groups of rows with the same column value
• HAVING: filters the groups subject to some condition
• SELECT: specifies which columns are to appear in the output
• ORDER: BY specifies the order of the output
Simple Queries
• The order of the clauses in the SELECT statement cannot be
changed. The only two mandatory clauses are the first two: SELECT
and FROM; the remainder are optional
4
9/14/2021
Simple Queries
• Example Retrieve all columns, all rows
• Because there are no restrictions specified in this query, the
WHERE clause is unnecessary and all columns are required. We
write this query as:
Simple Queries
• The following statement is an equivalent and shorter way of
expressing this query: SELECT * FROM Staff;
10
5
9/14/2021
Simple Queries
Example: Retrieve specific columns, all rows
• Produce a list of salaries for all staff, showing only the staff number, the first
and last names, and the salary details.
• SELECT staffNo, fName, IName, salary FROM Staff;
11
Simple Queries
12
6
9/14/2021
Simple Queries
13
14
7
9/14/2021
16
8
9/14/2021
17
18
9
9/14/2021
19
20
10
9/14/2021
21
22
11
9/14/2021
23
24
12
9/14/2021
25
26
13
9/14/2021
28
14
9/14/2021
29
30
15
9/14/2021
31
32
16
9/14/2021
33
34
17