SQL UNION Queries
What is the primary purpose of a union query in SQL?
- To create relationships between tables.
- To combine the result sets of two or more SELECT statements into a single result set.
- To update data across multiple tables simultaneously.
- To delete records based on conditions from different tables.
- Too update records in different tables.
UNION Query Restrictions
Which SQL operation is NOT typically allowed directly within a union query?
- Selecting data.
- Ordering the final result set.
- Filtering data.
- Updating data.
- Creating data.
UNION ALL vs UNION
What is the key difference between using 'UNION' and 'UNION ALL' when combining result sets in SQL?
- 'UNION ALL' automatically sorts the result set, while 'UNION' does not.
- 'UNION' includes duplicate rows, while 'UNION ALL' only includes distinct rows.
- 'UNION ALL' includes all rows, including duplicates, while 'UNION' removes duplicate rows.
- 'UNION' can only combine tables with the same number of columns, while 'UNION ALL' can combine tables with different number of columns.
- They are exactly the same and can be used interchangeably.
Ordering in UNION Queries
Where should the 'ORDER BY' clause be placed in a SQL query that uses 'UNION' to combine multiple 'SELECT' statements?
- Within each individual 'SELECT' statement.
- At the beginning of the entire query.
- At the end of the entire query, after the 'UNION' keyword.
- In the middle of the query.
- At the top of each select query
Number of Columns in UNION
What is a requirement when combining SELECT statements using UNION in SQL?
- The SELECT statements must select from the same table.
- The SELECT statements must select the same number of columns.
- The SELECT statements must filter the data with the same WHERE clause.
- The SELECT statements must order the data with the same ORDER BY clause.
- The SELECT statements must return different data types.
SQL JOIN Clauses
What type of JOIN returns only the rows that have matching values in both tables involved?
- LEFT JOIN
- RIGHT JOIN
- FULL OUTER JOIN
- INNER JOIN
- OUTER JOIN
LEFT JOIN Behavior
In a LEFT JOIN operation, if a row in the left table does not have a matching row in the right table, what values will be present for the columns from the right table in the result set?
- Zeroes
- Empty strings
- Undefined
- Null values
- Random values
Filtering with WHERE
If you need to limit the number of records displayed after running a query, which of the options best suit your needs?
- SORT BY
- ORDER BY
- WHERE
- LIMIT
- OFFSET
Filtering and Sorting Data
Which SQL clause is used to specify the order in which the rows should be returned in a query result?
- SORT BY
- WHERE
- GROUP BY
- HAVING
- ORDER BY
Sorting SQL Data
How can you sort the result set in descending order based on a column named 'date_column'?
- ORDER BY date_column ASC
- SORT BY date_column DESC
- ORDER date_column DESCENDING
- ORDER date_column DESC
- ORDER BY date_column ASCENDING