In a SQL query, what does the logical operator 'AND' do?
Explanation:
The AND operator requires both conditions to be true for the combined condition to be true.
In which scenario would a subquery be a more suitable choice than a JOIN operation?
Explanation:
Subqueries excel at providing dynamic filtering conditions for the main query. If the filtering relies on a separate query's results, using a subquery makes the logic clearer and more concise than attempting to achieve the same with JOINs.
By default, how does the 'ORDER BY' clause sort data?
Explanation:
If no specific order (ASC or DESC) is specified, ORDER BY defaults to sorting in ascending order.
How would you convert the text 'hello world' to uppercase in SQL?
Explanation:
UPPER()
is a string function that takes a string as an argument and returns the string converted to uppercase.
What is the purpose of a subquery in SQL?
Explanation:
A subquery is a query nested inside another query, used to fetch data that the main query then uses, effectively acting as a dynamic input for the main query.
Which of the following is NOT a valid SQL data type?
Explanation:
While some database systems have extensions or specific types for boolean values, standard SQL does not have a BOOLEAN data type.
Which SQL statement is used to remove rows from a table?
Explanation:
While both DELETE and TRUNCATE remove rows, DELETE is used to selectively remove rows based on a condition, while TRUNCATE removes all rows.
Which data type would be most suitable for storing a person's last name in a SQL database?
Explanation:
VARCHAR (Variable Character) is used for storing strings of text, making it appropriate for a last name which can vary in length.
How would you sort results in descending order by the 'date_created' column?
Explanation:
The 'DESC' keyword after the column name in the ORDER BY clause signals descending order sorting.
What type of join returns all rows from the left table, even if there are no matching rows in the right table?
Explanation:
A LEFT JOIN
returns all rows from the left table (the table mentioned before LEFT JOIN
) and the matching rows from the right table. If there are no matches, it fills in NULL
values for the columns from the right table.
You are using a subquery to fetch a list of product IDs from an 'Orders' table. What is the main purpose of using the DISTINCT keyword within this subquery?
Explanation:
The DISTINCT keyword ensures that the subquery's result set contains only unique values, removing any duplicate product IDs, which is essential for accurate comparisons or joins in the main query.
Which comparison operator means 'not equal to' in SQL?
Explanation:
Both '!=' and '<>' are used for 'not equal to' in SQL. They are interchangeable.
What is the primary clause used to retrieve data from a table in SQL?
Explanation:
The SELECT clause is the core of retrieving data in SQL. It specifies the columns you want to get from a table.
Which aggregate function would you use to find the highest value in a column?
Explanation:
MAX()
is an aggregate function that returns the maximum value in a set of values (typically a column).
What SQL clause is used to group rows with the same value in one or more columns into a summary row?
Explanation:
The GROUP BY clause is specifically designed to group rows based on identical values in specified columns, allowing for aggregate functions to be applied to each group.