What is the main purpose of the division operation in relational databases?
Think about queries that require matching all items from one set to another.
The division operation is used to find tuples in one relation that are related to all tuples in another relation. It helps answer queries like 'Find all entities related to every item in a set.'
Given two tables, StudentsCourses(StudentID, CourseID) and Courses(CourseID), which SQL query correctly finds students enrolled in all courses?
Count how many unique courses each student is enrolled in and compare it to the total number of courses.
Option D counts distinct courses per student and compares it to the total courses count, ensuring the student is enrolled in all courses. Other options either check partial matches or use incorrect operators.
Consider the following tables:
Suppliers(SupplierID)
Parts(PartID)
Supplies(SupplierID, PartID)
What does the query below return?
SELECT SupplierID FROM Supplies GROUP BY SupplierID HAVING COUNT(DISTINCT PartID) = (SELECT COUNT(*) FROM Parts);
Focus on the HAVING clause comparing counts of parts per supplier to total parts.
The query groups supplies by supplier and selects those whose count of distinct parts matches the total number of parts, meaning they supply all parts.
Which SQL query correctly implements the division operation to find employees who have completed all required trainings listed in Trainings(TrainingID) using NOT EXISTS?
Think about how double negation with NOT EXISTS can express 'for all' conditions.
Option C uses double NOT EXISTS to ensure no training exists that the employee has not completed, correctly implementing division. Other options either check partial completion or misuse EXISTS.
Given tables Projects(ProjectID), Employees(EmployeeID), and WorksOn(EmployeeID, ProjectID), which statement is true if the following query returns an empty set?
SELECT EmployeeID FROM WorksOn GROUP BY EmployeeID HAVING COUNT(DISTINCT ProjectID) = (SELECT COUNT(*) FROM Projects);
Consider what an empty result means for the count comparison in the HAVING clause.
The query filters employees who work on every project. An empty result means no employee meets this condition, so no one works on all projects.