TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

MySQL

MySQL Inline Views

Overview

In this tutorial, we will learn about MySQL inline views with example. An inline view is a special type of subquery that appears in the FROM clause.

A subquery that creates a derived table that can be used in the FROM clause of a SELECT statement
is called as an inline view.  Inline views are sometimes called  as virtual tables.

Syntax

SELECT…. FROM (subquery) AS  table_alias_name

When a derived table is used in a query, it should be given a table alias We can accomplish this with the AS clause that will act as the table alias.

Example

In the following query, the average of the sums of the population of each continent is determined:

mysql> SELECT *
-> FROM (SELECT Continent, SUM(Population) AS Continent_Population_Sum
-> FROM Country
-> GROUP BY Continent)
-> AS temp
-> ORDER BY Continent;


+—————+————————–+
| Continent | Continent_Population_Sum |
+—————+————————–+
| Asia | 3705025700 |
| Europe | 730074600 |
| North America | 482993000 |
| Africa | 784475000 |
| Oceania | 30401150 |
| Antarctica | 0 |
| South America | 353186400 |
+—————+————————–+
7 rows in set (0.00 sec)

 

MySQL Inline Views

Every table that appears in a FROM clause must have a name, so a subquery in the FROM clause must be
followed by a table alias. The SELECT in the FROM clause is a table subquery. Note that the subqueries in FROM clauses cannot be correlated with the outer query statement.

—

MySQL Tutorials

MySQL Tutorials on this website:

https://www.testingdocs.com/mysql-tutorials-for-beginners/

For more information on MySQL Database:

https://www.mysql.com/

Related Posts

DataGrip Desktop Shortcut

MySQL /

Launch DataGrip on Windows

DataGrip Download

MySQL /

Install DataGrip IDE on Windows 11

MySQL Workbench Windows 11

MySQL /

New MySQL Connection in Workbench

MySQL Command-line Client

MySQL /

Command-Line MySQL Client

Start MySQL Client

MySQL /

Start MySQL Client on Windows 11

‹ MySQL ANY Operator› Delete rows in a table using Subquery

Recent Posts

  • Update draw.io on Windows
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com