0% found this document useful (0 votes)
6 views6 pages

SQL JOINs and Conditions Practice

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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

SQL JOINs and Conditions Practice

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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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 [Link], [Link]

FROM Employees e

JOIN Departments d

ON [Link] = [Link];

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 [Link], [Link]

FROM Departments d

LEFT JOIN Employees e

ON [Link] = [Link];
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 [Link], [Link]

FROM Employees e

RIGHT JOIN Departments d

ON [Link] = [Link];

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 [Link], [Link]

FROM Employees e

LEFT JOIN Departments d

ON [Link] = [Link])

UNION

(SELECT [Link], [Link]

FROM Departments d

RIGHT JOIN Employees e

ON [Link] = [Link]);

Expected Output:

| Name | DepartmentName |

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

| John | HR |

| Alice | IT |

| Bob | NULL |

| NULL | Marketing |

| NULL | Sales |

You might also like