Q.1 Which SQL statement is used to extract data from a database?
GET
SELECT
EXTRACT
OPEN
Explanation - The SELECT statement is used to query and retrieve data from a database.
Correct answer is: SELECT
Q.2 Which clause is used to filter records in SQL?
WHERE
ORDER BY
GROUP BY
HAVING
Explanation - The WHERE clause is used to filter records based on specified conditions.
Correct answer is: WHERE
Q.3 What does SQL JOIN do?
Deletes rows
Combines rows from two or more tables
Updates rows
Creates a new table
Explanation - JOIN operations are used to combine rows from two or more tables based on a related column between them.
Correct answer is: Combines rows from two or more tables
Q.4 Which SQL keyword is used to sort the result-set?
SORT BY
ORDER BY
GROUP BY
ALIGN BY
Explanation - ORDER BY is used to sort the result set in ascending (ASC) or descending (DESC) order.
Correct answer is: ORDER BY
Q.5 What is the purpose of the SQL GROUP BY clause?
Filter rows
Combine rows based on aggregate functions
Sort rows
Delete duplicates
Explanation - GROUP BY groups rows sharing a property so aggregate functions (like SUM, COUNT) can be applied on them.
Correct answer is: Combine rows based on aggregate functions
Q.6 Which of the following SQL statements will remove all records from a table but not the table itself?
DELETE FROM table
DROP TABLE table
TRUNCATE TABLE table
REMOVE TABLE table
Explanation - TRUNCATE TABLE deletes all rows from a table without removing the table structure.
Correct answer is: TRUNCATE TABLE table
Q.7 Which aggregate function returns the total number of rows in a table?
SUM()
COUNT()
MAX()
AVG()
Explanation - COUNT() returns the number of rows that match a specified condition.
Correct answer is: COUNT()
Q.8 What is the difference between INNER JOIN and LEFT JOIN?
INNER JOIN returns all rows, LEFT JOIN only matching rows
INNER JOIN returns matching rows, LEFT JOIN returns all rows from left table
INNER JOIN deletes duplicates, LEFT JOIN keeps duplicates
No difference
Explanation - INNER JOIN returns rows with matching values in both tables; LEFT JOIN returns all rows from the left table, with NULLs for unmatched rows in the right table.
Correct answer is: INNER JOIN returns matching rows, LEFT JOIN returns all rows from left table
Q.9 Which SQL command is used to add a new column to an existing table?
ADD COLUMN
ALTER TABLE
INSERT COLUMN
MODIFY TABLE
Explanation - ALTER TABLE allows modifications to an existing table structure, including adding or removing columns.
Correct answer is: ALTER TABLE
Q.10 Which SQL statement is used to remove a table from a database?
DELETE TABLE
REMOVE TABLE
DROP TABLE
TRUNCATE TABLE
Explanation - DROP TABLE removes the table and all its data from the database permanently.
Correct answer is: DROP TABLE
Q.11 What is the result of a CROSS JOIN between two tables?
Rows with NULLs
Intersection of tables
Cartesian product of two tables
Only unique rows
Explanation - CROSS JOIN produces a Cartesian product, combining each row of the first table with each row of the second table.
Correct answer is: Cartesian product of two tables
Q.12 Which SQL keyword is used with aggregate functions to filter grouped data?
WHERE
ORDER BY
HAVING
FILTER BY
Explanation - HAVING is used to filter data after aggregation, unlike WHERE which filters before aggregation.
Correct answer is: HAVING
Q.13 Which SQL statement is used to change existing records in a table?
MODIFY
UPDATE
ALTER
CHANGE
Explanation - UPDATE is used to modify existing records in a table based on a condition specified in WHERE.
Correct answer is: UPDATE
Q.14 Which SQL keyword allows retrieving unique records from a table?
DISTINCT
UNIQUE
ONLY
LIMIT
Explanation - DISTINCT removes duplicate records from the result set, returning only unique values.
Correct answer is: DISTINCT
Q.15 Which SQL function is used to find the highest value in a column?
MAX()
TOP()
HIGHEST()
UPPER()
Explanation - MAX() returns the largest value in a specified column.
Correct answer is: MAX()
Q.16 What is a subquery in SQL?
A query inside another query
A query with multiple columns
A query that deletes data
A query that creates a table
Explanation - A subquery is a nested query used inside another SQL statement to perform intermediate calculations or filtering.
Correct answer is: A query inside another query
Q.17 Which SQL statement is used to combine the results of two SELECT statements?
UNION
MERGE
JOIN
INTERSECT
Explanation - UNION combines the results of two queries into a single result set, removing duplicates by default.
Correct answer is: UNION
Q.18 What is the purpose of an INDEX in SQL?
To store data permanently
To speed up query retrieval
To create a backup
To enforce constraints
Explanation - Indexes improve database performance by allowing faster retrieval of records based on indexed columns.
Correct answer is: To speed up query retrieval
Q.19 Which clause is used to limit the number of rows returned by a query in SQL?
LIMIT
TOP
ROWNUM
All of the above depending on SQL dialect
Explanation - Different SQL dialects use different keywords: LIMIT (MySQL, PostgreSQL), TOP (SQL Server), ROWNUM (Oracle) to limit result rows.
Correct answer is: All of the above depending on SQL dialect
Q.20 Which SQL statement creates a new table in a database?
CREATE TABLE
NEW TABLE
INSERT TABLE
MAKE TABLE
Explanation - CREATE TABLE defines a new table with specified columns and data types in the database.
Correct answer is: CREATE TABLE
Q.21 Which of the following is a characteristic of a PRIMARY KEY?
Can have NULL values
Uniquely identifies a row
Can be duplicated
Must be a string type
Explanation - PRIMARY KEY ensures each row is unique and cannot contain NULL values.
Correct answer is: Uniquely identifies a row
Q.22 Which SQL keyword is used to combine multiple conditions in a WHERE clause?
AND/OR
JOIN
GROUP
FILTER
Explanation - AND/OR are logical operators used to combine multiple conditions in a WHERE clause.
Correct answer is: AND/OR
Q.23 What does the SQL EXISTS operator do?
Checks if a subquery returns any rows
Checks for duplicates
Updates a row
Deletes rows
Explanation - EXISTS returns TRUE if the subquery produces at least one row, otherwise FALSE.
Correct answer is: Checks if a subquery returns any rows
Q.24 Which clause in SQL is used to combine data from multiple tables based on a related column?
JOIN
UNION
MERGE
GROUP BY
Explanation - JOIN is used to combine rows from two or more tables based on a related column between them.
Correct answer is: JOIN
