Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Uso de Subconsultas Internas en la Sección FROM | Subconsultas Anidadas
SQL Intermedio
course content

Contenido del Curso

SQL Intermedio

SQL Intermedio

1. Agrupamiento
2. Subconsultas Anidadas
3. Uniendo Tablas
4. DDL y DML en SQL

book
Uso de Subconsultas Internas en la Sección FROM

An inner subquery creates a table with which we then perform operations in the outer query.

From this, we can conclude that we can also use an inner query within the FROM section to select something from this table.

Let's consider an example where we need to work with employees whose salary is above a certain value. But instead of a WHERE clause, we will use an inner query:

123456
SELECT * FROM ( SELECT * From employees WHERE salary >= 70000 ) AS high_salary_employees
copy

We've created a new table using an inner subquery with which we can work and gather information.

Note

Notice that for such a table, it's essential to provide an alias.

When might this be useful?

Such a query is highly readable; sometimes, it can replace a WHERE clause.

Additionally, if you need to work not with the entire table but only with a filtered part, an inner subquery within the FROM section can be extremely handy.

Tarea
test

Swipe to show code editor

Your task is to retrieve the average budget (budget column) for all managerial departments from the department table. Use an inner subquery in the FROM section to filter only the managerial type of department. Also, use the alias manager_departments for this table so the task is checked correctly.

Note:

The response should have only one column, average_budget. This is an alias for the aggregate function AVG().

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 3
toggle bottom row

book
Uso de Subconsultas Internas en la Sección FROM

An inner subquery creates a table with which we then perform operations in the outer query.

From this, we can conclude that we can also use an inner query within the FROM section to select something from this table.

Let's consider an example where we need to work with employees whose salary is above a certain value. But instead of a WHERE clause, we will use an inner query:

123456
SELECT * FROM ( SELECT * From employees WHERE salary >= 70000 ) AS high_salary_employees
copy

We've created a new table using an inner subquery with which we can work and gather information.

Note

Notice that for such a table, it's essential to provide an alias.

When might this be useful?

Such a query is highly readable; sometimes, it can replace a WHERE clause.

Additionally, if you need to work not with the entire table but only with a filtered part, an inner subquery within the FROM section can be extremely handy.

Tarea
test

Swipe to show code editor

Your task is to retrieve the average budget (budget column) for all managerial departments from the department table. Use an inner subquery in the FROM section to filter only the managerial type of department. Also, use the alias manager_departments for this table so the task is checked correctly.

Note:

The response should have only one column, average_budget. This is an alias for the aggregate function AVG().

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 3
Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt