DBMS 3b(employee department location )
DBMS 3b(employee department location )
also tell the oral questions examiner can ask for this
To prepare for this practical, let's break down each question, providing sample SQL queries
and inserting test data to illustrate how to test each query. I'll also cover possible oral
questions the examiner might ask and concepts you should understand.
Table Creation
sql
sql
1. Find the names and salary of employees who earn the same as the minimum salary
for all departments.
sql
sql
3. Find employee id, last name, manager id, and manager's last name.
sql
sql
sql
3. Debugging: If a query doesn’t work, calmly check for syntax errors or table name
mismatches.
2. Joins: What types of joins are there? Why do we use a LEFT JOIN in question 3?
4. GROUP BY: Why is GROUP BY used in question 5? Can you use GROUP BY without
aggregate functions?
5. Difference between WHERE and HAVING: Where would you use HAVING instead of
WHERE ?
Understand query logic: For each query, know why each component (join, subquery,
condition) is necessary.
Here’s a list of oral exam questions based on the schema and queries provided, along with
model answers to help you prepare.
MIN() and MAX() : Find the smallest and largest values, respectively.
6. What is the purpose of the JOIN operation in SQL, and what types
of joins are there?
INNER JOIN: Returns only the rows where there is a match in both tables.
LEFT JOIN (or LEFT OUTER JOIN): Returns all rows from the left table and matched
rows from the right table. If there is no match, NULL is returned for columns from
the right table.
RIGHT JOIN (or RIGHT OUTER JOIN): Returns all rows from the right table and
matched rows from the left table.
FULL JOIN (or FULL OUTER JOIN): Returns all rows where there is a match in one of
the tables. Rows without matches get NULLs in the columns of the other table.
10. What are indexes in a database, and why are they important?
Answer: Indexes are database objects that improve the speed of data retrieval
operations. They function similarly to an index in a book, where it allows the database to
find rows faster by indexing columns. Indexes are important for enhancing performance,
15. In Query 4, how does SQL know to return employees hired after
'Jones'?
Answer: In Query 4, SQL first identifies the hire date of the employee with the last name
'Jones' using a subquery. Then, it compares this hire date with each employee's hire date
in the WHERE clause of the main query. Only employees hired after this date are
returned.