Which keyword used with UNION retains duplicate rows?
A. ALL
B. NARROW
C. STRICT
D. DISTINCT
Answer: Option A
Solution (By Examveda Team)
This question is about combining the results of multiple SELECT queries in MySQL. The UNION operator is used for this purpose. It takes the results of two or more SELECT statements and combines them into a single result set.By default, UNION removes duplicate rows. So, if the same row exists in multiple queries, it will only appear once in the final result.
The question asks about a keyword that keeps these duplicate rows.
The answer is Option A: ALL.
Here's how it works:
* UNION ALL combines the results of multiple SELECT queries, including any duplicate rows.
* UNION DISTINCT (or just UNION) combines the results, but removes duplicate rows.
Example
Let's say you have two tables, 'students' and 'employees', and you want to combine their data:
students table:
| Name | Age | |---|---| | John | 20 | | Jane | 22 | | John | 20 |
employees table:
| Name | Age | |---|---| | John | 25 | | Mary | 30 |
Using UNION ALL:
```sql SELECT * FROM students UNION ALL SELECT * FROM employees; ```
The result will be:
| Name | Age | |---|---| | John | 20 | | Jane | 22 | | John | 20 | | John | 25 | | Mary | 30 |
Notice that the row "John | 20" appears twice.
Using UNION DISTINCT:
```sql SELECT * FROM students UNION SELECT * FROM employees; ```
The result will be:
| Name | Age | |---|---| | John | 20 | | Jane | 22 | | John | 25 | | Mary | 30 |
Here, the row "John | 20" only appears once.
So, the ALL keyword is used with UNION to keep duplicate rows.
Related Questions on MySQL Miscellaneous
How is communication established with MySQL?
A. SQL
B. Network calls
C. A programming language like C++
D. APIs
Which type of database management system is MySQL?
A. Object-oriented
B. Hierarchical
C. Relational
D. Network
Join The Discussion