SQL Flashcards
How do you subset or filter data in SQL?
To subset or filter data in SQL, we use WHERE and HAVING clauses.
What is the difference between a WHERE clause and a HAVING clause in SQL?
WHERE:
WHERE clause operates on row data.
In the WHERE clause, the filter occurs before any groupings are made.
Aggregate functions cannot be used.
HAVING:
The HAVING clause operates on aggregated data.
HAVING is used to filter values from a group.
Aggregate functions can be used.
How are Union, Intersect, and Except used in SQL?
The Union operator combines the output of two or more SELECT statements, giving us unique results from all SELECT statements - no duplicates.
The Intersect operator returns the common records that are the results of 2 or more SELECT statements.
The Except operator returns the uncommon records that are the results of 2 or more SELECT statements.
What is a Subquery in SQL?
A Subquery in SQL is a query within another query. It is also known as a nested query or an inner query. Subqueries are used to enhance the data to be queried by the main query.
It is of two types - Correlated and Non-Correlated Query.