2. Introduction to SQL
Introduction to SQL
What is SQL?
– When a user wants to get some information
from a database file, he can issue a query.
1
1
– A query is a user–request to retrieve data or
information with a certain condition.
– SQL is a query language that allows user to
specify the conditions. (instead of algorithms)
3. Introduction to SQL
Introduction to SQL
Concept of SQL
– The user specifies a certain condition.
1
1
– The result of the query will then be stored in
form of a table.
– Statistical information of the data.
– The program will go through all the records
in the database file and select those records
that satisfy the condition.(searching).
4. Introduction to SQL
Introduction to SQL
How to involve SQL in FoxPro
– Before using SQL, the tables should be
opened.
1
1
– The SQL command can be entered directly
in the Command Window
– To perform exact matching, we should
SET ANSI ON
5. Basic structure of an SQL
Basic structure of an SQL
query
query
2
2
General
Structure
SELECT, ALL / DISTINCT, *,
AS, FROM, WHERE
Comparison IN, BETWEEN, LIKE "% _"
Grouping GROUP BY, HAVING,
COUNT( ), SUM( ), AVG( ), MAX( ), MIN( )
Display Order ORDER BY, ASC / DESC
Logical
Operators
AND, OR, NOT
Output INTO TABLE / CURSOR
TO FILE [ADDITIVE], TO PRINTER, TO SCREEN
Union UNION
6. field
field type
type width
width contents
contents
id numeric 4 student id number
name character 10 name
dob date 8 date of birth
sex character 1 sex: M / F
class character 2 class
hcode character 1 house code: R, Y, B,
G
dcode character 3 district code
remission logical 1 fee remission
mtest numeric 2 Math test score
2
2 The Situation:
Student Particulars
7. General Structure
General Structure
I
I
SELECT
SELECT [
[ALL / DISTINCT
ALL / DISTINCT]
] expr1
expr1 [
[AS
AS col1
col1],
], expr2
expr2 [
[AS
AS col2
col2]
] ;
;
FROM
FROM tablename
tablename WHERE
WHERE condition
condition
SELECT ...... FROM ...... WHERE ......
SELECT ...... FROM ...... WHERE ......
8. General Structure
General Structure
I
I
– The query will select rows from the source tablename and
output the result in table form.
– Expressions expr1, expr2 can be :
• (1) a column, or
• (2) an expression of functions and fields.
SELECT
SELECT [
[ALL / DISTINCT
ALL / DISTINCT]
] expr1
expr1 [
[AS
AS col1
col1],
], expr2
expr2 [
[AS
AS col2
col2]
] ;
;
FROM
FROM tablename
tablename WHERE
WHERE condition
condition
– And col1, col2 are their corresponding column names in the
output table.
9. General Structure
General Structure
I
I
– DISTINCT will eliminate duplication in the output while
ALL will keep all duplicated rows.
– condition can be :
• (1) an inequality, or
• (2) a string comparison
• using logical operators AND, OR, NOT.
SELECT
SELECT [
[ALL / DISTINCT
ALL / DISTINCT]
] expr1
expr1 [
[AS
AS col1
col1],
], expr2
expr2 [
[AS
AS col2
col2]
] ;
;
FROM
FROM tablename
tablename WHERE
WHERE condition
condition
10. General Structure
General Structure
I
I Before using SQL, open the student file:
USE student
USE student
eg. 1
eg. 1 List all the student records.
List all the student records.
SELECT * FROM student
id name dob sex class mtest hcode dcode remission
9801 Peter 06/04/86 M 1A 70 R SSP .F.
9802 Mary 01/10/86 F 1A 92 Y HHM .F.
9803 Johnny 03/16/86 M 1A 91 G SSP .T.
9804 Wendy 07/09/86 F 1B 84 B YMT .F.
9805 Tobe 10/17/86 M 1B 88 R YMT .F.
: : : : : : : : :
Result
11. General Structure
General Structure
I
I
eg. 2
eg. 2 List the names and house code of 1A students.
List the names and house code of 1A students.
SELECT name, hcode, class FROM student ;
WHERE class="1A"
Class
1
1A
A
1
1A
A
1
1A
A
1
1B
B
1
1B
B
:
:
Class
1
1A
A
1
1A
A
1
1A
A
1
1B
B
1
1B
B
:
:
class="1A"
12. General Structure
General Structure
I
I
name hcode class
Peter R 1A
Mary Y 1A
Johnny G 1A
Luke G 1A
Bobby B 1A
Aaron R 1A
: : :
Result
eg. 2
eg. 2 List the names and house code of 1A students.
List the names and house code of 1A students.
13. General Structure
General Structure
I
I
eg. 3
eg. 3 List the residential district of the Red House
List the residential district of the Red House
members.
members.
SELECT DISTINCT dcode FROM student ;
WHERE hcode="R"
dcode
HHM
KWC
MKK
SSP
TST
YMT
Result
15. Condition for "1B Girls":
Condition for "1B Girls":
1)
1) class =
class = "1B"
"1B"
2)
2) sex =
sex = "F"
"F"
3)
3) Both ( AND operator)
Both ( AND operator)
General Structure
General Structure
I
I
eg. 4
eg. 4 List the names and ages (1 d.p.) of 1B girls.
List the names and ages (1 d.p.) of 1B girls.
16. General Structure
General Structure
I
I
eg. 4
eg. 4 List the names and ages (1 d.p.) of 1B girls.
List the names and ages (1 d.p.) of 1B girls.
What is "age"?
What is "age"?
17. Functions:
Functions:
# days :
# days : DATE( ) – dob
DATE( ) – dob
# years :(DATE( ) – dob) / 365
# years :(DATE( ) – dob) / 365
1 d.p.:
1 d.p.: ROUND(__ , 1)
ROUND(__ , 1)
General Structure
General Structure
I
I
eg. 4
eg. 4 List the names and ages (1 d.p.) of 1B girls.
List the names and ages (1 d.p.) of 1B girls.
18. General Structure
General Structure
I
I
eg. 4
eg. 4 List the names and ages (1 d.p.) of 1B girls.
List the names and ages (1 d.p.) of 1B girls.
SELECT name, ROUND((DATE( )-dob)/365,1) AS age ;
FROM student WHERE class="1B" AND sex="F"
name age
Wendy 12.1
Kitty 11.5
Janet 12.4
Sandy 12.3
Mimi 12.2
Result
19. General Structure
General Structure
I
I
eg. 5
eg. 5 List the names, id of 1A students with no fee
List the names, id of 1A students with no fee
remission.
remission.
SELECT name, id, class FROM student ;
WHERE class="1A" AND NOT remission
name id class
Peter 9801 1A
Mary 9802 1A
Luke 9810 1A
Bobby 9811 1A
Aaron 9812 1A
Ron 9813 1A
Gigi 9824 1A
: : :
Result
20. Comparison
Comparison
II
II expr
expr IN (
IN ( value1
value1,
, value2
value2,
, value3
value3)
)
expr
expr BETWEEN
BETWEEN value1
value1 AND
AND value2
value2
expr
expr LIKE "%_"
LIKE "%_"
21. Comparison
Comparison
II
II
eg. 6
eg. 6 List the students who were born on Wednesday
List the students who were born on Wednesday or
or
Saturdays.
Saturdays.
SELECT name, class, CDOW(dob) AS
bdate ; FROM student ;
WHERE DOW(dob) IN (4,7)
name class bdate
Peter 1A Wednesday
Wendy 1B Wednesday
Kevin 1C Saturday
Luke 1A Wednesday
Aaron 1A Saturday
: : :
Result
22. Comparison
Comparison
II
II
eg. 7
eg. 7 List the students who were not born in January,
List the students who were not born in January, March,
March,
June, September.
June, September.
SELECT name, class, dob FROM student ;
WHERE MONTH(dob) NOT IN (1,3,6,9)
name class dob
Wendy 1B 07/09/86
Tobe 1B 10/17/86
Eric 1C 05/05/87
Patty 1C 08/13/87
Kevin 1C 11/21/87
Bobby 1A 02/16/86
Aaron 1A 08/02/86
: : :
Result
23. Comparison
Comparison
II
II
eg. 8
eg. 8 List the 1A students whose Math test score is
List the 1A students whose Math test score is between
between
80 and 90 (incl.)
80 and 90 (incl.)
SELECT name, mtest FROM student ;
WHERE class="1A" AND ;
mtest BETWEEN 80 AND 90
name mtest
Luke 86
Aaron 83
Gigi 84
Result
24. Comparison
Comparison
II
II
eg. 9
eg. 9 List the students whose names start with "T".
List the students whose names start with "T".
SELECT name, class FROM student ;
WHERE name LIKE "T%"
name class
Tobe 1B
Teddy 1B
Tim 2A
Result
25. Comparison
Comparison
II
II
eg. 10
eg. 10 List the Red house members whose names contain
List the Red house members whose names contain "a" as
"a" as
the 2nd letter.
the 2nd letter.
SELECT name, class, hcode FROM student ;
WHERE name LIKE "_a%" AND hcode="R"
name class hcode
Aaron 1A R
Janet 1B R
Paula 2A R
Result
26. Grouping
Grouping
III
III
SELECT ...... FROM ...... WHERE
SELECT ...... FROM ...... WHERE condition
condition ;
;
GROUP BY
GROUP BY groupexpr
groupexpr [HAVING
[HAVING requirement
requirement]
]
Group functions:
Group functions:
COUNT( ), SUM( ), AVG( ), MAX( ), MIN( )
COUNT( ), SUM( ), AVG( ), MAX( ), MIN( )
– groupexpr specifies the related rows to be grouped
as one entry. Usually it is a column.
– WHERE condition specifies the condition of
individual rows before the rows are group.
HAVING requirement specifies the condition
involving the whole group.
28. COUNT( )
COUNT( )
Group By Class
Group By Class
1
1A
A
COUNT( )
COUNT( )
1
1B
B
COUNT( )
COUNT( )
1
1C
C
1
1A
A
1
1B
B
1
1C
C
Student
Student
class
1
1A
A
1
1A
A
1
1A
A
1
1B
B
1
1B
B
1
1B
B
1
1B
B
1
1B
B
1
1B
B
1
1C
C
1
1C
C
1
1C
C
29. Grouping
Grouping
III
III
SELECT class, COUNT(*) FROM student ;
GROUP BY class
class cnt
1A 10
1B 9
1C 9
2A 8
2B 8
2C 6
eg. 11
eg. 11 List the number of students of each class.
List the number of students of each class.
Result
31. Group By Class
Group By Class
AVG( )
AVG( )
AVG( )
AVG( )
AVG( )
AVG( )
1
1A
A
1
1B
B
1
1C
C
Student
Student
class
1
1A
A
1
1A
A
1
1A
A
1
1B
B
1
1B
B
1
1B
B
1
1B
B
1
1B
B
1
1B
B
1
1C
C
1
1C
C
1
1C
C
32. Grouping
Grouping
III
III
eg. 12
eg. 12 List the average Math test score of each class.
List the average Math test score of each class.
SELECT class, AVG(mtest) FROM student ;
GROUP BY class
class avg_mtest
1A 85.90
1B 70.33
1C 37.89
2A 89.38
2B 53.13
2C 32.67
Result
33. Grouping
Grouping
III
III
eg. 13
eg. 13 List the number of girls of each district.
List the number of girls of each district.
SELECT dcode, COUNT(*) FROM student ;
WHERE sex="F" GROUP BY dcode
dcode cnt
HHM 6
KWC 1
MKK 1
SSP 5
TST 4
YMT 8
Result
34. Grouping
Grouping
III
III
eg. 14
eg. 14 List the max. and min. test score of Form 1
List the max. and min. test score of Form 1 students
students
of each district.
of each district.
SELECT MAX(mtest), MIN(mtest), dcode ;
FROM student ;
WHERE class LIKE "1_" GROUP BY dcode
max_mtest min_mtest dcode
92 36 HHM
91 19 MKK
91 31 SSP
92 36 TST
75 75 TSW
88 38 YMT
Result
35. Grouping
Grouping
III
III
eg. 15
eg. 15 List the average Math test score of the boys in
List the average Math test score of the boys in each
each
class. The list should not contain class with
class. The list should not contain class with less than 3 boys.
less than 3 boys.
SELECT AVG(mtest), class FROM student ;
WHERE sex="M" GROUP BY class ;
HAVING COUNT(*) >= 3
avg_mtest class
86.00 1A
77.75 1B
35.60 1C
86.50 2A
56.50 2B
Result
36. Display Order
Display Order
IV
IV
SELECT ...... FROM ...... WHERE ......
SELECT ...... FROM ...... WHERE ......
GROUP BY ..... ;
GROUP BY ..... ;
ORDER BY
ORDER BY colname
colname ASC / DESC
ASC / DESC
37. Display Order
Display Order
IV
IV
SELECT name, id FROM student ;
WHERE sex="M" AND class="1A" ORDER BY name
eg. 16
eg. 16 List the boys of class 1A, order by their names.
List the boys of class 1A, order by their names.
name id
Peter 9801
Johnny 9803
Luke 9810
Bobby 9811
Aaron 9812
Ron 9813
ORDER BY
dcode
name id
Aaron 9812
Bobby 9811
Johnny 9803
Luke 9810
Peter 9801
Ron 9813
Result
38. Display Order
Display Order
IV
IV
SELECT name, id, class, dcode FROM
student ;
WHERE class="2A" ORDER BY dcode
eg. 17
eg. 17 List the 2A students by their residential district.
List the 2A students by their residential district.
name id class dcode
Jimmy 9712 2A HHM
Tim 9713 2A HHM
Samual 9714 2A SHT
Rosa 9703 2A SSP
Helen 9702 2A TST
Joseph 9715 2A TSW
Paula 9701 2A YMT
Susan 9704 2A YMT
Result
39. Display Order
Display Order
IV
IV
SELECT COUNT(*) AS cnt, dcode FROM
student ;
GROUP BY dcode ORDER BY cnt DESC
eg. 18
eg. 18 List the number of students of each district
List the number of students of each district
(in desc. order).
(in desc. order).
cnt docode
11 YMT
10 HHM
10 SSP
9 MKK
5 TST
2 TSW
1 KWC
1 MMK
1 SHT
Result
40. Display Order
Display Order
IV
IV
SELECT name, class, hcode FROM student ;
WHERE sex="M" ORDER BY hcode, class
eg. 19
eg. 19 List the boys of each house order by the
List the boys of each house order by the classes.
classes.
(2-level ordering)
(2-level ordering)
41. Display Order
Display Order
IV
IV
name hcode class
Bobby B 1A
Teddy B 1B
Joseph B 2A
Zion B 2B
Leslie B 2C
Johnny G 1A
Luke G 1A
Kevin G 1C
George G 1C
: : :
Result
Order
by
class
Blue
House
Green
House
:
:
Order
by
hcode
42. Output
Output
V
V
INTO TABLE tablename the output table is saved as a
database file in the disk.
INTO CURSOR temp the output is stored in the
working memory temporarily.
TO FILE filename [ADDITIVE] output to a text file.
(additive = append)
TO PRINTER send to printer.
TO SCREEN display on screen.
43. Output
Output
V
V
eg. 20
eg. 20 List the students in desc. order of their names and
List the students in desc. order of their names and save the
save the
result as a database file name.dbf.
result as a database file name.dbf.
SELECT * FROM student ;
ORDER BY name DESC INTO TABLE name.dbf
id name dob sex class mtest hcode dcode remission
9707 Zion 07/29/85 M 2B 51 B MKK .F.
9709 Yvonne 08/24/85 F 2C 10 R TST .F.
9804 Wendy 07/09/86 F 1B 84 B YMT .F.
9819 Vincent 03/15/85 M 1C 29 Y MKK .F.
9805 Tobe 10/17/86 M 1B 88 R YMT .F.
9713 Tim 06/19/85 M 2A 91 R HHM .T.
9816 Teddy 01/30/86 M 1B 64 B SSP .F.
: : : : : : : : :
Result
44. Output
Output
V
V
eg. 21
eg. 21 Print the Red House members by their classes, sex
Print the Red House members by their classes, sex and
and
name.
name.
SELECT class, name, sex FROM student ;
WHERE hcode="R" ;
ORDER BY class, sex DESC, name TO PRINTER
class name sex
1A Aaron M
1A Peter M
1A Ron M
1B Tobe M
1B Janet F
1B Kitty F
1B Mimi F
: : :
Result
45. Union, Intersection and
Union, Intersection and
Difference of Tables
Difference of Tables
3
3
A B
The union of A and B (AB)
A table containing all the rows from A and B.
46. Union, Intersection and
Union, Intersection and
Difference of Tables
Difference of Tables
3
3
The intersection of A and B (AB)
A table containing only rows that appear in both A and B.
A B
47. Union, Intersection and
Union, Intersection and
Difference of Tables
Difference of Tables
3
3
The difference of A and B (A–B)
A table containing rows that appear in A but not in B.
A B
48. 3
3
Consider the members of the Bridge Club and
Consider the members of the Bridge Club and
the Chess Club. The two database files have
the Chess Club. The two database files have
the same structure:
the same structure:
The Situation:
Bridge Club & Chess Club
field type width contents
id numeric 4 student id number
name character 10 name
sex character 1 sex: M / F
class character 2 class
49. Union, Intersection and
Union, Intersection and
Difference of Tables
Difference of Tables
3
3
Before using SQL, open the two tables:
Before using SQL, open the two tables:
Bridge [A] Chess [B]
id name sex class id name sex class
1 9812 Aaron M 1A 1 9802 Mary F 1A
2 9801 Peter M 1A 2 9801 Peter M 1A
3 9814 Kenny M 1B 3 9815 Eddy M 1B
4 9806 Kitty F 1B 4 9814 Kenny M 1B
5 9818 Edmond M 1C 5 9817 George M 1C
: : : : : : : :
SELECT A
SELECT A
USE bridge
USE bridge
SELECT B
SELECT B
USE chess
USE chess
50. Union, Intersection and
Union, Intersection and
Difference of Tables
Difference of Tables
3
3
SELECT * FROM bridge ;
UNION ;
SELECT * FROM chess ;
ORDER BY class, name INTO TABLE party
eg. 22
eg. 22 The two clubs want to hold a joint party.
The two clubs want to hold a joint party. Make a list of all
Make a list of all
students. (Union)
students. (Union)
SELECT ...... FROM ...... WHERE ...... ;
SELECT ...... FROM ...... WHERE ...... ;
UNION ;
UNION ;
SELECT ...... FROM ...... WHERE ......
SELECT ...... FROM ...... WHERE ......
Result
51. Union, Intersection and
Union, Intersection and
Difference of Tables
Difference of Tables
3
3
SELECT * FROM bridge ;
WHERE id IN ( SELECT id FROM chess ) ;
TO PRINTER
eg. 23
eg. 23 Print a list of students who are members of both
Print a list of students who are members of both clubs.
clubs.
(Intersection)
(Intersection)
SELECT ...... FROM
SELECT ...... FROM table1
table1 ;
;
WHERE
WHERE col
col IN ( SELECT
IN ( SELECT col
col FROM
FROM table2
table2 )
)
Result
52. Union, Intersection and
Union, Intersection and
Difference of Tables
Difference of Tables
3
3
SELECT * FROM bridge ;
WHERE id NOT IN ( SELECT id FROM chess ) ;
INTO TABLE diff
eg. 24
eg. 24 Make a list of students who are members of the
Make a list of students who are members of the Bridge
Bridge
Club but not Chess Club. (Difference)
Club but not Chess Club. (Difference)
SELECT ...... FROM
SELECT ...... FROM table1
table1 ;
;
WHERE
WHERE col
col NOT IN ( SELECT
NOT IN ( SELECT col
col FROM
FROM table2
table2 )
)
Result
53. Multiple Tables:
Multiple Tables:
4
4
• SQL provides a convenient operation to
SQL provides a convenient operation to
retrieve information from multiple
retrieve information from multiple
tables.
tables.
• This operation is called
This operation is called join
join.
.
• The join operation will
The join operation will combine
combine the tables
the tables
into
into one large table with all possible
one large table with all possible
combinations
combinations (Math: Cartesian Product), and then
(Math: Cartesian Product), and then
it will filter
it will filter the rows of this combined table to
the rows of this combined table to
yield useful
yield useful information.
information.
55. 4
4
Each student should learn a musical instrument.
Each student should learn a musical instrument.
Two database files:
Two database files: student.dbf
student.dbf &
& music.dbf
music.dbf
The common field:
The common field: student id
student id
field
field type
type width
width contents
contents
id
id numeric
numeric 4
4 student id number
student id number
type
type character
character 10
10 type of the music instrument
type of the music instrument
The Situation:
Music Lesson
SELECT A
SELECT A
USE student
USE student
SELECT B
SELECT B
USE music
USE music
56. Natural Join
Natural Join
4
4
A
A Natural Join
Natural Join is a join operation that joins two
is a join operation that joins two
tables by
tables by their common column. This
their common column. This
operation is similar to the setting relation of two
operation is similar to the setting relation of two
tables.
tables.
SELECT a.comcol, a.
SELECT a.comcol, a.col1
col1, b.
, b.col2
col2,
, expr1
expr1,
, expr2
expr2 ;
;
FROM
FROM table1
table1 a,
a, table2
table2 b ;
b ;
WHERE a.
WHERE a.comcol
comcol = b.
= b.comcol
comcol
58. SELECT s.class, s.name, s.id, m.type ;
FROM student s, music m ;
WHERE s.id=m.id ORDER BY class, name
Natural Join
Natural Join
4
4
class name id type
1A Aaron 9812 Piano
1A Bobby 9811 Flute
1A Gigi 9824 Recorder
1A Jill 9820 Piano
1A Johnny 9803 Violin
1A Luke 9810 Piano
1A Mary 9802 Flute
: : : :
Result
eg. 25
eg. 25 Make a list of students and the instruments they
Make a list of students and the instruments they learn.
learn.
(Natural Join)
(Natural Join)
59. eg. 26
eg. 26 Find the number of students learning piano in
Find the number of students learning piano in each
each
class.
class.
Natural Join
Natural Join
4
4
Three Parts :
Three Parts :
(1)
(1) Natural Join.
Natural Join.
(2)
(2) Condition:
Condition: m.type="Piano"
m.type="Piano"
(3)
(3) GROUP BY class
GROUP BY class
61. eg. 26
eg. 26 Find the number of students learning piano in
Find the number of students learning piano in each
each
class.
class.
SELECT s.class, COUNT(*) ;
FROM student s, music m ;
WHERE s.id=m.id AND m.type="Piano" ;
GROUP BY class ORDER BY class
Natural Join
Natural Join
4
4
class cnt
1A 4
1B 2
1C 1
Result
62. An
An Outer Join
Outer Join is a join operation that includes
is a join operation that includes
rows that have a match, plus rows that do not
rows that have a match, plus rows that do not
have a match in the other table.
have a match in the other table.
Outer Join
Outer Join
4
4
63. eg. 27
eg. 27 List the students who have not yet chosen an
List the students who have not yet chosen an
instrument. (No match)
instrument. (No match)
Outer Join
Outer Join
4
4
No match
No match
Music
Music
id
id type
type
Student
Student
9801
9801
id
id name
name class
class
64. eg. 27
eg. 27 List the students who have not yet chosen an
List the students who have not yet chosen an
instrument. (No match)
instrument. (No match)
SELECT class, name, id FROM student ;
WHERE id NOT IN ( SELECT id FROM music ) ;
ORDER BY class, name
Outer Join
Outer Join
4
4
Result
class name id
1A Mandy 9821
1B Kenny 9814
1B Tobe 9805
1C Edmond 9818
1C George 9817
: : :
65. eg. 28
eg. 28 Make a checking list of students and the
Make a checking list of students and the instruments they learn.
instruments they learn.
The list should also
The list should also contain the students without an instrument.
contain the students without an instrument.
(Outer Join)
(Outer Join)
Outer Join
Outer Join
4
4
67. SELECT s.class, s.name, s.id, m.type ;
FROM student s, music m ;
WHERE s.id=m.id ;
Outer Join
Outer Join
4
4
UNION ;
SELECT class, name, id, "" ;
FROM student ;
WHERE id NOT IN ( SELECT id FROM music ) ;
ORDER BY 1, 2
eg. 28
eg. 28
68. Outer Join
Outer Join
4
4
empty
class name id
1A Mandy 9821
1B Kenny 9814
1B Tobe 9805
1C Edmond 9818
1C George 9817
: : :
No Match
class name id type
1A Aaron 9812 Piano
1A Bobby 9811 Flute
1A Gigi 9824 Recorder
1A Jill 9820 Piano
1A Johnny 9803 Violin
1A Luke 9810 Piano
1A Mary 9802 Flute
: : : :
Natural Join
class name id type
1A Aaron 9812 Piano
1A Bobby 9811 Flute
1A Gigi 9824 Recorder
1A Jill 9820 Piano
1A Johnny 9803 Violin
1A Luke 9810 Piano
1A Mandy 9821
1A Mary 9802 Flute
1A Peter 9801 Piano
1A Ron 9813 Guitar
1B Eddy 9815 Piano
1B Janet 9822 Guitar
1B Kenny 9814
1B Kitty 9806 Recorder
: : : :
Outer Join