Creating a View Based on Multiple Tables
The following view is created to display the employees name along with their department and job title with respect to their id. The INNER JOIN keyword is used to match the id of employees, departments and jobs table to provide the respective result.
CREATE VIEW employee_details AS
SELECT e.name, d.name AS department, j.title AS job_title
FROM employees e
INNER JOIN departments d ON e.department_id = d.id
INNER JOIN jobs j ON e.job_id = j.id;
SELECT * FROM employee_details;
Output:
Explanation: In the above query, we have creates a virtual table named employee_details
that combines data from the employees
, departments
, and jobs
tables. It selects the employeeâs name, their departmentâs name, and their job title by joining these tables based on their respective IDs.
MariaDB Create View
Views in MariaDB are powerful tools that allow us to create virtual tables based on the result set of a SELECT query. They provide a way to simplify complex queries, improve security by limiting access to certain columns,, and enhance performance by precomputing expensive operations. In this article, we will explore how to create views in MariaDB along with multiple examples.
Contact Us