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.
What does the asterisk (*) symbol represent when used in a SELECT statement?
Explanation:
In SQL, the asterisk (*) is a shorthand to select all columns from a table when used in the SELECT clause.
What potential issue should be considered when using correlated subqueries?
Explanation:
Correlated subqueries execute for each row of the outer query, potentially leading to performance bottlenecks, especially with large datasets. Proper indexing and optimization are crucial.
What does SQL stand for?
Explanation:
SQL stands for Structured Query Language. It's a standardized language for managing and interacting with relational databases.
You want to select the department with the highest average salary. What SQL clause would you use to filter the grouped results based on the calculated average salary?
Explanation:
HAVING is used to filter groups after the GROUP BY clause, making it suitable for conditions involving aggregate functions like AVG used for calculating the average salary.
Which SQL statement is used to add new rows into a table?
Explanation:
The INSERT statement is used to insert new rows with data into an existing table within a database.
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 difference between CURDATE()
and NOW()
in SQL?
Explanation:
CURDATE()
returns only the current date in 'YYYY-MM-DD' format, while NOW()
returns both the current date and time.
How would you select the top 5 highest-scoring games from a table named 'games' with a column called 'score'?
Explanation:
This query sorts the games by score in descending order and then uses LIMIT to retrieve only the top 5.
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.
What type of join returns all rows from both tables, regardless of whether there is a match?
Explanation:
A FULL OUTER JOIN
returns all rows from both the left and right tables. If there are no matches on one side, it fills in NULL
values for the corresponding columns.
Which SQL function would you use to combine the first and last names from two different columns into a single column?
Explanation:
CONCAT()
is a string function that takes two or more strings as arguments and concatenates them into a single string.
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.
Which keyword is used in conjunction with the UPDATE statement to specify the conditions for updating rows?
Explanation:
The WHERE clause is crucial with UPDATE as it defines which rows should be modified. Without it, all rows would be updated.
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.