Learn Python

Learn Data Structure & Algorithm

Learn Numpy

Learn Pandas

Learn Matplotlib

Learn Seaborn

Learn Statistics

Learn Math

Learn MATLAB

Learn Machine learning

Learn Github

Learn OpenCV

Learn Deep Learning

MySQL Introduction

MySQL Setup

MySQL Operators

MySQL Basic Works

MySQL Create Table

MySQL insert and get values

MySQL Condition

MySQL GROUP BY

MySQL Case

MySQL sorting and calculate avg,sum,count

MySQL Update

MySQL Time

MySQL String

MySQL Rollback & Commit

MySQL Join and Concatenate

MySQL Index

MySQL Date

MySQL View

MYSQL With Python

Learn MongoDB

Learn Web scraping

Learn Excel

Learn Power BI

Learn Tableau

Learn Docker

Learn Hadoop

Everything about sql view

Sometimes what happens is that we write a big code and we need to use that code multiple times. Writing the code each time is not good. So what we can do is that we can save that code anywhere and then we can use that code how many times we want. In MySQL view do this for you.

To do this, save the code and give a name to that saved code and when we want that code, just write the name, and the code written inside that name will be executed.

Syntax:
CREATE VIEW view_name
AS
Write your code

Syntax to use the view:
SELECT * FROM view_name

Let's see an example:

Suppose you write a code to join two tables:
SELECT
personal_doc.id,personal_doc.name,personal_doc.age,personal_doc.gender,city.city
FROM personal_doc
JOIN city
ON personal_doc.city=city.cid;

Let's create a view:
CREATE VIEW My_view
AS
SELECT
personal_doc.id,personal_doc.name,personal_doc.age,personal_doc.gender,city.city
FROM personal_doc
JOIN city
ON personal_doc.city=city.cid;

How to use the view:
SELECT * FROM My_view;

How to update view?

Syntax:
ALTER VIEW view_name
AS
Change the code
Let's see an example: We create a view where we join two tables. Now we will edit that code and will join three tables.

ALTER VIEW view_name
AS
SELECT
personal_doc.id,personal_doc.name,personal_doc.age,personal_doc.gender,city.city
FROM personal_doc
JOIN city
ON personal_doc.city=city.cid
JOIN other_doc
ON personal_doc.city=other_doc.roll;

CodersAim is created for learning and training a self learner to become a professional from beginner. While using CodersAim, you agree to have read and accepted our terms of use, privacy policy, Contact Us

© Copyright All rights reserved www.CodersAim.com. Developed by CodersAim.