What does SQL do?
Introduction to the SQL
language
Lesson Outcomes
All of you will be able to describe and recall
the syntax involved with a select command
All of you will use=
1. Select*
2. In
3. Between
4. Revise comparison operators
5. Revise boolean operators
. Most of you will be able to create commands
in order to interogate data within tables
Recap
Working on little databases
is kids stuf
SQL
Structured
Query
Language
The structure
SELECT FROM
WHERE
The structure
<Tablename(s
)>
SELE FROM WHER
CT
E
<condition>
<ColumnNam
e(s)>
The structure of a select command
<Tablename(s
)>
SELE FROM WHER
CT
E
<condition>
<ColumnNam
e(s)>
SELECT <ColumnName(s)> FROM <TableName> WHERE
<condition>
Boring tedious warning
All programs and applications may have
slight variations on the syntax of SQL
We will go by what Edexcel are referring
to(It will be just a standard version)
You need to be able to interpret what
they are asking you
First example
Open the database document: Marksheet
SELECT Name FROM Marksheet WHERE
Assign1 > 50
What would you expect as a result?
First example
Name
Aisha
Katharine
Fiona
Gareth
Manjit
Ubaid
Gemma
Alex
Philip
Second example
Open the database document: Marksheet
SELECT Name, Average FROM Marksheet WHERE
Average > 0 AND Average < 65
SELECT Name, Assign1, Assign2, Assign3 FROM
Marksheet WHERE Assign1 <= 40 AND Assign2 <= 40
AND Assign3 <= 40
SELECT Name FROM Marksheet WHERE Assign1 < 50
OR Assign2 < 50 OR Assign3 < 50
What would you expect as a result?
Second example
Using = Select*
SELECT * FROM Marksheet WHERE Average > 70
What does the *
represent?
Second example
Using = Select*
SELECT * FROM Marksheet WHERE Average > 70
Name
Assign1
Assign2
Assign3
Average
Fiona
100
87
72
86
Gareth
86
65
69
73
Philip
90
86
85
87
Second example
Using = IN
SELECT Name, Average WHERE IN (Aisha ,Jo , Mark ,
Shan) gives
IN Specifies multiple
values
Second example
Using = IN
SELECT Name, Average FROM Marksheet WHERE IN
(Aisha ,Jo , Mark , Shan) gives
IN Specifies multiple
Name
Averag
e
values
Aisha
Jo
Mark
58
45
13
Second example
Using = BETWEEN
SELECT * FROM Marksheet WHERE Average BETWEEN
60 AND 75
Second example
Using = BETWEEN
SELECT * FROM Marksheet WHERE Average BETWEEN
60 AND 75
Name
Assign1
Assign2
Assign3
Average
Katharine 75
76
48
70
Gareth
86
65
69
73
Manjit
66
64
68
66
Gemma
52
78
78
69
Really good, try it!
http://sqlzoo.n
et/