Skip to content

meshal10613/Level-2-Assignment-3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Vehicle Rental System - Database Design & SQL Queries

Overview & Objectives

This assignment is designed to evaluate your understanding of database table design, ERD relationships and SQL queries. You will work with a simplified Vehicle Rental System database.

Part 1: ERD Design

ERD Design

Part 2: SQL Queries

This section contains SQL queries written based on the designed database schema.
Each query demonstrates specific SQL concepts such as joins, subqueries, filtering, grouping, and aggregation.

The expected results for each query can be verified using the Sample Query Results (QUERY.md) file.


Query 1: JOIN

Objective

Retrieve booking information along with:

  • Customer name
  • Vehicle name

Concepts Used

  • SELECT
  • INNER JOIN

Explanation

This query uses inner join to combine data from the bookings, users, and vehicles tables. It retrieves the customer name and vehicle name for each booking. Only records with matching users and vehicles are included.


Query 2: EXISTS

Objective

Find all vehicles that have never been booked.

Concepts Used

  • NOT EXISTS
  • Subquery

Explanation

The subquery checks whether a booking exists for each vehicle. The not exists condition ensures that only vehicles with no associated bookings are returned.


Query 3: WHERE

Objective

Retrieve all available vehicles of a specific type (e.g., cars).

Concepts Used

  • SELECT
  • WHERE

Explanation

This query filters vehicles based on availability and vehicle type. Only vehicles that are available and classified as cars are retrieved.


Query 4: GROUP BY and HAVING

Objective

Find the total number of bookings for each vehicle and display only those vehicles that have more than two bookings.

Concepts Used

  • GROUP BY
  • HAVING
  • COUNT

Explanation

This query groups booking records by vehicle and counts the number of bookings per vehicle using the count() function. The having clause filters the grouped results to show only vehicles with more than two bookings.


(Viva Practice - Progress, Not Perfection)

Question 1 What is a foreign key and why is it important in relational databases?

Question 2 What is the difference between WHERE and HAVING clauses in SQL?

Question 3 What is a primary key and what are its characteristics?

Question 4 What is the difference between INNER JOIN and LEFT JOIN in SQL?

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published