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.
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 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.
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.
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.
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.
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 does SQL stand for?
Explanation:
SQL stands for Structured Query Language. It's a standardized language for managing and interacting with relational databases.
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.
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.
What is the key difference between the IN and EXISTS operators when used with subqueries?
Explanation:
IN compares a value against a list of values returned by a subquery. EXISTS checks whether the subquery returns any rows at all, regardless of the values.
What is the purpose of the 'LIMIT' clause in SQL?
Explanation:
LIMIT is used to control how many rows are included in the query result, helping manage the amount of data returned.
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.
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.
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.
Which comparison operator means 'not equal to' in SQL?
Explanation:
Both '!=' and '<>' are used for 'not equal to' in SQL. They are interchangeable.
What SQL clause is used to filter rows in a result set based on specific conditions?
Explanation:
The WHERE clause is used to specify conditions that rows must meet to be included in the query results.
To modify existing data in a table, which SQL statement would you use?
Explanation:
The UPDATE statement in SQL allows you to change the values in existing rows of a table based on your criteria.
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 is the purpose of the COUNT()
function in SQL?
Explanation:
COUNT()
is an aggregate function used to count the number of rows in a table or the number of rows that meet a specific condition in a query.