Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

VIEW Statement



SQL CREATE VIEW Statement


In SQL, a VIEW is a virtual table that is based on the result set of a SELECT query. It doesn't store data physically but represents data from one or more tables. The CREATE VIEW statement is used to define a new view in the database.

Here's the basic syntax of the CREATE VIEW statement:


CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;


Explanation of each part:

Example:

Let's say we have two tables: employees and departments. We want to create a view that shows the names of employees along with their departments.


CREATE VIEW employee_department_view AS
SELECT employees.employee_id, employees.first_name, employees.last_name, departments.department_name
FROM employees
JOIN departments ON employees.department_id = departments.department_id;


In this example:

Once the view is created, you can query it like a regular table:


SELECT * FROM employee_department_view;


This query will return the data from the employee_department_view view, which will look like a combined table of employee details with their respective department names.



Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java