M.
Chinyuku Database Systems 2023
MySQL Practical 4- Retrieving
information using the SELECT Query
• The SQL SELECT command is used to fetch data from the MySQL database.
Exercise 4
1. Use SQL script to create a database named exercise 4
2. Create the tables given below in database exercise 4
Note: The allowable values for the City column for all tables = Chinhoyi, Harare, Bulawayo,
Masvingo, and Karoi only
Page 1|5
M. Chinyuku Database Systems 2023
Page 2|5
M. Chinyuku Database Systems 2023
1. Retrieve all tuples
Syntax
SELECT * FROM table_name;
Retrieve all records from Customer table
Select * from Customer;
2. Retrieve Specific tuples
Syntax
SELECT * FROM table_name
WHERE condition;
a) Retrieve from Customer table customers from Chinhoyi
SELECT * FROM Customer
WHERE City = 'Chinhoyi';
Page 3|5
M. Chinyuku Database Systems 2023
b) Retrieve all order details of supplier number S100
SELECT * FROM Orders
WHERE SupplierNumber ='S100';
3. Project Particular Columns
Syntax
SELECT field1, field2…, fieldn FROM table_name;
a) List all product names from the Product table
Select ProductName FROM Product;
4. Selecting and Projecting particular rows and columns
• Combining SELECT and PROJECT operation
• You can use a WHERE clause to combine row selection with column selection
Syntax
SELECT field1, field2, …, fieldn
FROM table_name
WHERE condition;
a) List all Product IDs, Supplier numbers and the quantity whose order date is 12 October 2018
SELECT ProductID, SupplierNumber, Quantity
FROM Orders
where Orderdate ='2018-10-12';
Page 4|5
M. Chinyuku Database Systems 2023
Activity
Use the exercise 3 database that you created in Practical 3
Lecturer (LecturerID, LecturerName, Office)
Course (CourseID, CourseName, Department)
Class (ClassID, LecturerID, CourseID, Venue, Time, Day)
Perform the following queries
1. Retrieve all records from Course table
2. Retrieve courses details for courses in the ICT department
3. Find details of lecturers who are in office E8
4. Find class details of courses taught at 0800hrs on Mondays
5. List all the names of departments
6. List course names offered in the Engineering department
7. List all courses taught on Monday whose venue is NEC3
Page 5|5