SQL_Advanced_Practice_Questions
SQL_Advanced_Practice_Questions
Question 1
Table: Employees
|------------|-----------|--------------|
|1 | John | 101 |
|2 | Alice | 102 |
|3 | Bob | 101 |
|4 | Carol | 103 |
SQL Query:
Expected Output:
|------------|-----------|--------------|
|1 | John | 101 |
|2 | Alice | 102 |
|3 | Bob | 101 |
|4 | Carol | 103 |
Question 2
Tables:
Departments:
| DepartmentID | DepartmentName |
SQL Practice Questions with JOINs and Conditions
|--------------|----------------|
| 101 | HR |
| 102 | IT |
| 103 | Marketing |
Employees:
|------------|-----------|--------------|
|1 | John | 101 |
|2 | Alice | 102 |
|3 | Bob | 101 |
|4 | Carol | 103 |
SQL Query:
FROM Employees e
JOIN Departments d
ON e.DepartmentID = d.DepartmentID;
Expected Output:
| Name | DepartmentName |
|-----------|----------------|
| John | HR |
| Alice | IT |
| Bob | HR |
SQL Practice Questions with JOINs and Conditions
| Carol | Marketing |
Question 3
Tables:
Departments:
| DepartmentID | DepartmentName |
|--------------|----------------|
| 101 | HR |
| 102 | IT |
| 103 | Marketing |
| 104 | Sales |
Employees:
|------------|-----------|--------------|
|1 | John | 101 |
|2 | Alice | 102 |
|3 | Bob | 101 |
SQL Query:
FROM Departments d
ON d.DepartmentID = e.DepartmentID;
SQL Practice Questions with JOINs and Conditions
Expected Output:
| DepartmentName | Name |
|----------------|-----------|
| HR | John |
| HR | Bob |
| IT | Alice |
| Marketing | NULL |
| Sales | NULL |
Question 4
Tables:
Departments:
| DepartmentID | DepartmentName |
|--------------|----------------|
| 101 | HR |
| 102 | IT |
| 103 | Marketing |
Employees:
|------------|-----------|--------------|
|1 | John | 101 |
|2 | Alice | 102 |
|3 | Bob | 105 |
SQL Practice Questions with JOINs and Conditions
SQL Query:
FROM Employees e
ON e.DepartmentID = d.DepartmentID;
Expected Output:
| DepartmentName | Name |
|----------------|-----------|
| HR | John |
| IT | Alice |
| Marketing | NULL |
Question 5
Tables:
Departments:
| DepartmentID | DepartmentName |
|--------------|----------------|
| 101 | HR |
| 102 | IT |
| 103 | Marketing |
| 104 | Sales |
Employees:
SQL Practice Questions with JOINs and Conditions
|------------|-----------|--------------|
|1 | John | 101 |
|2 | Alice | 102 |
|3 | Bob | 105 |
SQL Query:
FROM Employees e
ON e.DepartmentID = d.DepartmentID)
UNION
FROM Departments d
ON e.DepartmentID = d.DepartmentID);
Expected Output:
| Name | DepartmentName |
|-----------|----------------|
| John | HR |
| Alice | IT |
| Bob | NULL |
| NULL | Marketing |
| NULL | Sales |