Online Coding Lessons SQL and Database Basics 2 — Questions and Answers
Question 1: Which SQL keyword removes duplicate rows from a SELECT result?
- UNIQUE
- DISTINCT (Correct answer)
- NODUPE
- FILTER
Correct answer: DISTINCT
The DISTINCT keyword, used right after SELECT, eliminates duplicate rows so each value appears only once in the results.
Question 2: What SQL clause is used to combine rows from two or more tables based on a related column?
- MERGE
- COMBINE
- JOIN (Correct answer)
- LINK
Correct answer: JOIN
The JOIN clause is used to combine rows from two or more tables based on a related (usually matching) column between them.
Question 3: Which SQL aggregate function returns the total number of rows in a result set?
- SUM()
- TOTAL()
- COUNT() (Correct answer)
- SIZE()
Correct answer: COUNT()
COUNT() is an aggregate function that returns the number of rows that match a specified condition.
Question 4: What does the UPDATE command do in SQL?
- Adds a new column to a table
- Changes existing data in one or more rows (Correct answer)
- Creates a brand new table
- Refreshes the database connection
Correct answer: Changes existing data in one or more rows
The UPDATE statement modifies the values of existing records in a table, usually with a WHERE clause to target specific rows.
Question 5: In SQL, what does the wildcard character % represent when used with the LIKE operator?
- Exactly one character
- Any single digit
- Any sequence of zero or more characters (Correct answer)
- A literal percent sign only
Correct answer: Any sequence of zero or more characters
The % wildcard in a LIKE pattern matches any sequence of zero or more characters, making it useful for partial-text searches.
Question 6: Which SQL command is used to create a new database table?
- BUILD TABLE
- MAKE TABLE
- NEW TABLE
- CREATE TABLE (Correct answer)
Correct answer: CREATE TABLE
CREATE TABLE is the SQL DDL command used to define and create a new table with specified columns and data types.
Question 7: What is the purpose of the GROUP BY clause in SQL?
- Sorts rows from largest to smallest
- Joins two tables on a common column
- Groups rows sharing the same value for use with aggregate functions (Correct answer)
- Removes rows that have NULL values
Correct answer: Groups rows sharing the same value for use with aggregate functions
GROUP BY groups rows with the same values in specified columns so aggregate functions like SUM() or COUNT() can be applied to each group.
Which SQL keyword removes duplicate rows from a SELECT result?