From the course: MySQL Advanced Topics
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Creating a view - MySQL Tutorial
From the course: MySQL Advanced Topics
Creating a view
- [Bill] Hi, I'm Bill Weinman. In MySQL, you can save a query as a view and you can use that view as if it were a table. This is very simple and useful. I've copied this block of SQL from the chapter two exercise file. I'll go ahead and use album to open the album database. And here's a useful query that gets the track duration as minutes and seconds. And you notice that I'm using the div and mod operators to get the minutes and seconds from the duration column, which is stored as just seconds. I'll go ahead and I'll execute this and you see that we get this result, which is our track table, but with the duration as minutes and seconds. Now let's say I want to use that query over and over. It's useful, I might want to use it a lot, so I'll save it as a view. I use create view to create the view. I name it TrackView. The as clause is where you put the SELECT statement that you're going to store. So I'm going to go ahead and execute all of that and you see we've successfully created the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.