Showing 1–10 of 57 questions
Which SQL command is used to retrieve data from a database?
A
SELECT
B
RETRIEVE
C
GET
D
FETCH
Correct Answer:
A. SELECT
Explanation:
SELECT is the standard SQL command used to retrieve or query data from one or more tables in a database.
What does the WHERE clause do in SQL?
A
Sorts the results
B
Filters rows based on specified conditions
C
Groups the data
D
Joins multiple tables
Correct Answer:
B. Filters rows based on specified conditions
Explanation:
The WHERE clause is used to filter records that meet specified conditions in a SQL query.
Which keyword is used to eliminate duplicate rows in SQL results?
A
UNIQUE
B
DISTINCT
C
DIFFERENT
D
EXCLUDE
Correct Answer:
B. DISTINCT
Explanation:
The DISTINCT keyword removes duplicate rows from the result set of a query.
What is the correct syntax for inserting data into a table?
A
INSERT INTO table_name VALUES (value1, value2, value3);
B
INSERT table_name (value1, value2, value3);
C
ADD INTO table_name VALUES (value1, value2, value3);
D
INSERT VALUES table_name (value1, value2, value3);
Correct Answer:
A. INSERT INTO table_name VALUES (value1, value2, value3);
Explanation:
INSERT INTO is the correct SQL syntax for inserting new records into a table, followed by the table name and VALUES clause.
Which SQL aggregate function returns the total sum of a numeric column?
A
TOTAL()
B
ADD()
C
SUM()
D
COUNT()
Explanation:
The SUM() function calculates the total sum of all values in a numeric column.
What is the purpose of the JOIN clause in SQL?
A
To combine rows from two or more tables based on related columns
B
To delete records from a table
C
To update multiple rows at once
D
To create a backup of a table
Correct Answer:
A. To combine rows from two or more tables based on related columns
Explanation:
JOIN combines rows from two or more tables based on a relationship between the columns (usually foreign key relationship).
Which type of JOIN returns only matching rows from both tables?
A
LEFT JOIN
B
RIGHT JOIN
C
INNER JOIN
D
FULL OUTER JOIN
Correct Answer:
C. INNER JOIN
Explanation:
INNER JOIN returns only the rows that have matching values in both tables being joined.
What will be the output of: SELECT COUNT(*) FROM employees;
A
The number of columns in the employees table
B
The total number of rows in the employees table
C
The names of all employees
D
An error message
Correct Answer:
B. The total number of rows in the employees table
Explanation:
COUNT(*) returns the total number of rows in the specified table, including NULL values.
Which SQL clause is used to sort the result set in ascending or descending order?
A
WHERE
B
ORDER BY
C
GROUP BY
D
HAVING
Correct Answer:
B. ORDER BY
Explanation:
The ORDER BY clause sorts the result set in ascending (ASC) or descending (DESC) order. Default is ascending.
What is the difference between WHERE and HAVING clauses?
A
WHERE filters rows before grouping; HAVING filters groups after grouping
B
HAVING filters rows; WHERE filters groups
C
They are identical and interchangeable
D
WHERE is used with JOIN; HAVING is used with SELECT
Correct Answer:
A. WHERE filters rows before grouping; HAVING filters groups after grouping
Explanation:
WHERE filters individual rows before GROUP BY is applied, while HAVING filters the grouped results after GROUP BY is applied.