SQL Queries
Joins
Aggregate Functions
Group By & Having
Relational Algebra
100

SQL command to retrieve all rows from the Employee table.

SELECT * FROM Employee;

100

SQL query to combine rows from two tables where they have matching values.

INNER JOIN

100

SQL command to count number of employees.  

SELECT COUNT(*) FROM Employee;  

100

Purpose of GROUP BY.

Groups rows based on column values.

100

Operator used for filtering rows.

Selection (σ)

200

SQL command to update salary of employee with ID=101 to 50000.

UPDATE Employee SET Salary = 50000 WHERE EmpID = 101;

200

Which join returns all rows from left table and matched rows from right?

LEFT JOIN

200

Function to find the highest salary.

MAX(Salary)  

200

SQL to count employees in each department. 

SELECT DNO, COUNT(*) 

FROM Employee 

GROUP BY DNO;

200

Operator used for choosing columns.

Projection (π)

300

What does the DISTINCT keyword do in SQL?

What does the DISTINCT keyword do in SQL?

300

Write a query to list all employees with their department names.

SELECT E.Name, D.DName 

FROM Employee E 

JOIN Department D ON E.DNO = D.DNumber;

300

Find average salary of employees in department 10.

SELECT AVG(Salary) 

FROM Employee 

WHERE DNO = 10;

300

Difference between WHERE and HAVING.

WHERE filters rows before grouping; HAVING filters groups after grouping.

300

Difference between Union and Cartesian Product.

Union = combines tuples (same schema); Cartesian Product = all combinations.

400

SQL command to delete all records but keep the table structure.

TRUNCATE TABLE TableName;

400

Which join includes unmatched rows from both tables?

FULL OUTER JOIN

400

What will SUM(NULL,10,20) return?

30 (NULL ignored)

400

Find departments with average salary > 40000.

SELECT DNO, AVG(Salary) 

FROM Employee 

GROUP BY DNO 

HAVING AVG(Salary) > 40000;

400

Expression for employees with salary > 50000.

σ Salary > 50000 (Employee)

500

Difference between DELETE and DROP.

DELETE removes rows, keeps structure; DROP removes table completely.  

500

Difference between CROSS JOIN and INNER JOIN.

Difference between CROSS JOIN and INNER JOIN.

500

Which aggregate function returns number of unique values?

COUNT(DISTINCT column)

500

Can we use aggregate functions in WHERE clause?

No, only in HAVING

500

Expression for names of employees working in Dept 10.

Expression for names of employees working in Dept 10.

M
e
n
u