May 2020
Beginner
564 pages
14h 9m
English
In this section, we will learn how to create a view when writing queries. To create a view, use the following syntax:
CREATE VIEW nameofview AS SELECT col1, col2, co1n FROM tablename WHERE condition;
Let's take a query and place it into a view with the following code:
USE lahmansbaseballdb; CREATE VIEW playergameinfo ASSELECT p.playerid, birthyear, a.yearid, a.teamid, G_defense AS defensegames, H AS numberofhitsFROM appearances AS aJOIN people AS pON p.playerid = a.playeridJOIN batting AS bON a.playerid = b.playeridAND a.yearid = b.yearid AND a.teamid = b.teamidWHERE b.yearid = 2017 AND H <> 0;
Once this view is created, you will be able to query data from the view, as shown in the following query: ...
Read now
Unlock full access