Search⌘ K

Answer: Using INNER JOIN

Understand how to write SELECT queries using INNER JOIN to combine related data from multiple tables. Explore the use of table aliases, the USING keyword, and WHERE filters with LEFT and RIGHT JOINs to handle various query scenarios and improve data retrieval.

Solution

The solution is given below:

MySQL
/* The query to apply INNER JOIN */
SELECT e.EmpName, p.ProjectName
FROM Employees AS e
INNER JOIN Projects AS p ON e.EmpID = p.EmpID;

Explanation

The explanation of the solution code is given below:

  • Line 2: The SELECT query selects EmpName and ProjectName. The e.EmpName refers to the EmpName column from the Employees table (aliased as e), and p.ProjectName refers to the ProjectName column from the Projects table (aliased as p).

  • Line 3: The data is retrieved from the Employees table.

  • Line 4: The INNER JOIN is applied with Employees and Projects on the EmpID column in both the tables.

Recall of relevant concepts

We have covered the following concepts in this question:

    ...