0% found this document useful (0 votes)
2 views

SQL_Advanced_Practice_Questions

The document contains SQL practice questions focused on JOIN operations and conditions using Employees and Departments tables. It includes multiple queries with expected outputs demonstrating INNER JOIN, LEFT JOIN, RIGHT JOIN, and UNION operations. Each question provides a clear structure of tables, SQL queries, and the anticipated results.

Uploaded by

ahiatiemmanuel77
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

SQL_Advanced_Practice_Questions

The document contains SQL practice questions focused on JOIN operations and conditions using Employees and Departments tables. It includes multiple queries with expected outputs demonstrating INNER JOIN, LEFT JOIN, RIGHT JOIN, and UNION operations. Each question provides a clear structure of tables, SQL queries, and the anticipated results.

Uploaded by

ahiatiemmanuel77
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

SQL Practice Questions with JOINs and Conditions

Question 1

Table: Employees

| EmployeeID | Name | DepartmentID |

|------------|-----------|--------------|

|1 | John | 101 |

|2 | Alice | 102 |

|3 | Bob | 101 |

|4 | Carol | 103 |

SQL Query:

SELECT * FROM Employees;

Expected Output:

| EmployeeID | Name | DepartmentID |

|------------|-----------|--------------|

|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:

| EmployeeID | Name | DepartmentID |

|------------|-----------|--------------|

|1 | John | 101 |

|2 | Alice | 102 |

|3 | Bob | 101 |

|4 | Carol | 103 |

SQL Query:

SELECT e.Name, d.DepartmentName

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:

| EmployeeID | Name | DepartmentID |

|------------|-----------|--------------|

|1 | John | 101 |

|2 | Alice | 102 |

|3 | Bob | 101 |

SQL Query:

SELECT d.DepartmentName, e.Name

FROM Departments d

LEFT JOIN Employees e

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:

| EmployeeID | Name | DepartmentID |

|------------|-----------|--------------|

|1 | John | 101 |

|2 | Alice | 102 |

|3 | Bob | 105 |
SQL Practice Questions with JOINs and Conditions

SQL Query:

SELECT d.DepartmentName, e.Name

FROM Employees e

RIGHT JOIN Departments d

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

| EmployeeID | Name | DepartmentID |

|------------|-----------|--------------|

|1 | John | 101 |

|2 | Alice | 102 |

|3 | Bob | 105 |

SQL Query:

(SELECT e.Name, d.DepartmentName

FROM Employees e

LEFT JOIN Departments d

ON e.DepartmentID = d.DepartmentID)

UNION

(SELECT e.Name, d.DepartmentName

FROM Departments d

RIGHT JOIN Employees e

ON e.DepartmentID = d.DepartmentID);

Expected Output:

| Name | DepartmentName |

|-----------|----------------|

| John | HR |

| Alice | IT |

| Bob | NULL |

| NULL | Marketing |

| NULL | Sales |

You might also like