From the course: MySQL Advanced Topics

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Creating a subquery

Creating a subquery - MySQL Tutorial

From the course: MySQL Advanced Topics

Creating a subquery

- [Bill] Hi, I'm Bill Weinman. A sub-select is effectively a nested query. In SQL, the result of a SELECT statement may be used as a data source for another query, just as you would use a table. This usage is called a sub-select. I've copied this block of SQL from the chapter two exercise file. I'm going to go ahead and I'm going to execute this USE world statement to open the world database. We'll be using that for this lesson. And then I'm going to create this table with two columns, both of them text columns, and we'll insert three rows into that table. And notice that the rows have a two character state code and then four digits. And likewise, the second column has a two digit country code and four digits. And we're just going to insert three rows of that stuff into this table. I'm going to go ahead and execute all of this. We'll start with the DROP TABLE IF EXISTS, and execute all of that. And you see there's our table with the three rows in it. Now I'm going to use substrings to…

Contents