0% found this document useful (0 votes)
60 views

MySQL Practical 4

This document discusses using SELECT queries in MySQL. It provides examples of retrieving all data, specific data using a WHERE clause, and projecting particular columns. The exercises at the end ask the reader to perform queries on tables in a database called "exercise 3" including retrieving all records, filtering by department or time/day, and projecting specific columns.

Uploaded by

crybert zinyama
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

MySQL Practical 4

This document discusses using SELECT queries in MySQL. It provides examples of retrieving all data, specific data using a WHERE clause, and projecting particular columns. The exercises at the end ask the reader to perform queries on tables in a database called "exercise 3" including retrieving all records, filtering by department or time/day, and projecting specific columns.

Uploaded by

crybert zinyama
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy