Workshop - Week 8 Mysql Practical Exercise
Workshop - Week 8 Mysql Practical Exercise
Exercise 1
This exercise is similar to week 5. Students at this stage should be illustrated how to
create tables, alter tables, and write complex SQL queries.
Note: Use SQL commands to create the database, tables, records, and Queries.
sid sname rating age sid bid Day bid bname colour
Sailors Reserves
2. Enter the test data for the three tables as shown above.
1
(1,1,'1998-08-11'),
(2,22,'1998-01-11');
3. Formulate SQL query to find the sailor ID, boat name, and colour of those
boats reserved on 9/8/98.
4. Formulate SQL query to find the names of sailors who have reserved boat
103.
SELECT sailors.sname
from sailors
JOIN reserves on sailors.sid = reserves.sid
WHERE reserves.bid=103
2
5. Formulate SQL query to find the names of sailors who have reserved a red
boat.
SELECT sailors.sname
from sailors
JOIN reserves on sailors.sid = reserves.sid
JOIN boats on boats.bid = reserves.bid
WHERE boats.colour='red';
6. The above commands are JOIN queries. Explain the concept of join.
A join is a SQL procedure that establishes a relation between two or more
rows and columns by creating a relationship between them depending on
matched attributes. In a SQL database system, join statements are used for the
bulk of complex queries. Join is a query that retrieves data from two tables
and combines them together just to create a single collection of information.
It's being used to merge columns from two or more tables by using data that
seem to be similar between both.