Explicación del UNION ALL (#23885)
* Explicación del UNION ALL Explicación con ejemplo del UNION ALL * Update index.md
This commit is contained in:
committed by
Randell Dawson
parent
4439b7080f
commit
3880122696
@ -24,7 +24,7 @@ SELECT 'aaaaa'
|
|||||||
|
|
||||||
Salida
|
Salida
|
||||||
|
|
||||||
```text
|
```
|
||||||
+-----------+
|
+-----------+
|
||||||
| aaaaa |
|
| aaaaa |
|
||||||
+-----------+
|
+-----------+
|
||||||
@ -45,8 +45,19 @@ SELECT StudentID, FullName FROM student WHERE studentID BETWEEN 1 AND 5
|
|||||||
```
|
```
|
||||||
|
|
||||||
Salida
|
Salida
|
||||||
|
```
|
||||||
\`\` \`texto + ----------- + -------------------------------- + | StudentID | Nombre completo | + ----------- + -------------------------------- + | 1 | Monique Davis | | 2 | Teri Gutierrez | | 3 | Spencer Pautier | | 4 | Louis Ramsey | | 5 | Alvin Greene | | 7 | Maximo.Smith@freeCodeCamp.org | | 8 | Michael.Roach@freeCodeCamp.ort | + ----------- + -------------------------------- + 7 filas en conjunto (0,00 seg)
|
+ ----------- + -------------------------------- +
|
||||||
|
| StudentID | Nombre completo |
|
||||||
|
+ ----------- + -------------------------------- +
|
||||||
|
| 1 | Monique Davis |
|
||||||
|
| 2 | Teri Gutierrez |
|
||||||
|
| 3 | Spencer Pautier |
|
||||||
|
| 4 | Louis Ramsey |
|
||||||
|
| 5 | Alvin Greene |
|
||||||
|
| 7 | Maximo.Smith@freeCodeCamp.org |
|
||||||
|
| 8 | Michael.Roach@freeCodeCamp.ort |
|
||||||
|
+ ----------- + -------------------------------- +
|
||||||
|
7 filas en conjunto (0,00 seg)
|
||||||
```
|
```
|
||||||
## SQL UNION ALL Operator
|
## SQL UNION ALL Operator
|
||||||
|
|
||||||
@ -57,6 +68,38 @@ Salida
|
|||||||
|
|
||||||
SQL Statement
|
SQL Statement
|
||||||
```
|
```
|
||||||
|
### Union All
|
||||||
|
Se usa la cláusula UNION ALL cuando se desea que si un registro de SQL A es el mismo del SQL B no se muestre en uno solo:
|
||||||
|
|
||||||
|
Si corremos el siguiente Query con union el resultado será:
|
||||||
|
|
||||||
|
```
|
||||||
|
SELECT CustomerName FROM Customers
|
||||||
|
WHERE City IN ('Paris','London')
|
||||||
|
AND customername = 'Around the Horn'
|
||||||
|
union
|
||||||
|
SELECT CustomerName FROM Customers
|
||||||
|
WHERE City IN ('Paris','London')
|
||||||
|
AND customername = 'Around the Horn';
|
||||||
|
|
||||||
|
Number of Records: 1
|
||||||
|
CustomerName
|
||||||
|
Around the Horn
|
||||||
|
```
|
||||||
|
Pero si corremos el mismo Query con UNION ALL el resultado no eliminará la columna repetida:
|
||||||
|
```
|
||||||
|
SELECT CustomerName FROM Customers
|
||||||
|
WHERE City IN ('Paris','London')
|
||||||
|
AND customername = 'Around the Horn'
|
||||||
|
union all
|
||||||
|
SELECT CustomerName FROM Customers
|
||||||
|
WHERE City IN ('Paris','London')
|
||||||
|
|
||||||
|
Number of Records: 2
|
||||||
|
CustomerName
|
||||||
|
Around the Horn
|
||||||
|
Around the Horn
|
||||||
|
```
|
||||||
|
|
||||||
sql SELECCIONAR expresión1, expresión2, ... expresión _n DE las tablas \[DÓNDE condiciones\] UNION TODO SELECCIONAR expresión1, expresión2, ... expresión_ n DE las tablas \[DÓNDE condiciones\]; \`\` \`
|
sql SELECCIONAR expresión1, expresión2, ... expresión _n DE las tablas \[DÓNDE condiciones\] UNION TODO SELECCIONAR expresión1, expresión2, ... expresión_ n DE las tablas \[DÓNDE condiciones\]; \`\` \`
|
||||||
|
|
||||||
@ -65,3 +108,5 @@ Al igual que con todas estas cosas de SQL, hay MUCHO MÁS que lo que está en es
|
|||||||
Espero que al menos esto te dé suficiente para empezar.
|
Espero que al menos esto te dé suficiente para empezar.
|
||||||
|
|
||||||
Consulte el manual de su administrador de base de datos y diviértase probando diferentes opciones usted mismo.
|
Consulte el manual de su administrador de base de datos y diviértase probando diferentes opciones usted mismo.
|
||||||
|
|
||||||
|
SQL para el union all se usó desde: https://www.w3schools.com/sql/trysql.asp?filename=trysql_op_in
|
||||||
|
Reference in New Issue
Block a user