give 50 MCQ of SQL query which are asked in the campus placement and most important .
level
is medium,difficult all includes
Here are 50 important SQL MCQs (medium + difficult) with answers, commonly asked in campus
placements. These cover queries, concepts, joins, subqueries, indexes, normalization, constraints,
aggregate functions, etc.
SQL MCQs for Campus Placement (50 Questions)
1. Which SQL keyword is used to remove duplicate rows in a query result?
A) UNIQUE
B) DISTINCT
C) DELETE
D) DIFFERENT
Answer: B) DISTINCT
2. What is the default sorting order of the ORDER BY clause?
A) Descending
B) Random
C) Ascending
D) None
Answer: C) Ascending
3. Which of the following is used to combine rows from two or more tables, based
on a related column?
A) UNION
B) JOIN
C) GROUP BY
D) INTERSECT
Answer: B) JOIN
4. Which JOIN returns only the matching rows from both tables?
A) LEFT JOIN
B) FULL OUTER JOIN
C) INNER JOIN
D) CROSS JOIN
Answer: C) INNER JOIN
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 1/20
5. Which query will return the 5 highest salaries from an Employee table?
A) SELECT TOP 5 salary FROM Employee ORDER BY salary DESC;
B) SELECT salary FROM Employee ORDER BY salary LIMIT 5;
C) SELECT salary FROM Employee ORDER BY salary DESC FETCH FIRST 5 ROWS ONLY;
D) All of the above (depends on DBMS)
Answer: D) All of the above
6. In SQL, which clause is used to filter the results of aggregate functions?
A) WHERE
B) HAVING
C) ORDER BY
D) GROUP BY
Answer: B) HAVING
7. What is the output of the query?
sql
SELECT COUNT(*) FROM Students WHERE marks > 50;
A) Sum of marks
B) Number of students with marks > 50
C) Maximum marks
D) Error
Answer: B) Number of students with marks > 50
8. What will this query return?
sql
SELECT AVG(salary) FROM Employee;
A) Median salary
B) Average salary
C) Sum of salaries
D) Maximum salary
Answer: B) Average salary
9. Which operator is used for pattern matching in SQL?
A) LIKE
B) MATCH
C) COMPARE
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 2/20
D) IN
Answer: A) LIKE
10. Which of these SQL keywords is used to retrieve unique values?
A) SELECT UNIQUE
B) SELECT DISTINCT
C) SELECT DIFFERENT
D) SELECT ONLY
Answer: B) SELECT DISTINCT
11. Which of the following can be used with a subquery?
A) SELECT
B) INSERT
C) UPDATE
D) All of the above
Answer: D) All of the above
12. Which constraint ensures that a column cannot have NULL values?
A) UNIQUE
B) NOT NULL
C) CHECK
D) DEFAULT
Answer: B) NOT NULL
13. What is the result of a CROSS JOIN?
A) Matches only related rows
B) Cartesian product of two tables
C) Removes duplicates
D) Inner join result
Answer: B) Cartesian product of two tables
14. Which SQL statement is correct to rename a table?
A) RENAME TABLE old TO new;
B) ALTER TABLE old RENAME TO new;
C) CHANGE TABLE old new;
D) MODIFY TABLE old new;
Answer: B) ALTER TABLE old RENAME TO new;
15. The keyword used to eliminate duplicates when using aggregate functions:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 3/20
A) ALL
B) DISTINCT
C) UNIQUE
D) NO DUPLICATE
Answer: B) DISTINCT
16. What does TRUNCATE TABLE do?
A) Removes structure and data
B) Removes all rows but keeps table structure
C) Deletes specific rows
D) None
Answer: B) Removes all rows but keeps table structure
17. Difference between DELETE and TRUNCATE?
A) DELETE is DDL, TRUNCATE is DML
B) DELETE can use WHERE, TRUNCATE cannot
C) DELETE resets identity, TRUNCATE doesn’t
D) All of the above
Answer: B) DELETE can use WHERE, TRUNCATE cannot
18. Which function returns the current date and time in SQL Server?
A) NOW()
B) CURRENT_DATE()
C) GETDATE()
D) SYSDATE()
Answer: C) GETDATE()
19. Which of these clauses is used to group rows that have the same values?
A) ORDER BY
B) GROUP BY
C) HAVING
D) DISTINCT
Answer: B) GROUP BY
20. What does SELECT * FROM emp WHERE dept IN ('HR', 'IT'); do?
A) Select employees from HR only
B) Select employees from HR or IT
C) Syntax error
D) None
Answer: B) Select employees from HR or IT
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 4/20
21. Which function is used to count the number of rows, including NULL values?
A) COUNT(column_name)
B) COUNT()
C) COUNT_ALL()
D) COUNT_ROWS()
Answer: B) COUNT()
22. The SQL clause used to restrict groups is:
A) WHERE
B) HAVING
C) GROUP BY
D) LIMIT
Answer: B) HAVING
23. Which of these is a correct syntax to create an index?
A) CREATE INDEX index_name ON table(column);
B) ADD INDEX index_name TO table(column);
C) NEW INDEX table column;
D) ALTER INDEX index_name ON table(column);
Answer: A) CREATE INDEX index_name ON table(column);
24. What will the following SQL do?
sql
SELECT dept, COUNT(*)
FROM Employee
GROUP BY dept
ORDER BY COUNT(*) DESC;
A) List departments and number of employees in ascending order
B) List departments and number of employees in descending order
C) Show only one department
D) Error
Answer: B) List departments and number of employees in descending order
25. Which type of subquery returns only one value?
A) Multi-row
B) Single-row
C) Correlated
D) None
Answer: B) Single-row
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 5/20
26. What is a correlated subquery?
A) Subquery that runs independently
B) Subquery that refers to columns from outer query
C) Subquery without WHERE
D) Subquery with multiple SELECT
Answer: B) Subquery that refers to columns from outer query
27. Which keyword is used with a subquery to compare a value to a list of values?
A) ANY / ALL
B) SOME
C) BOTH
D) EXISTS
Answer: A) ANY / ALL
28. What does the SQL keyword EXISTS do?
A) Returns true if subquery returns at least one row
B) Returns count of rows
C) Returns all rows
D) Checks schema
Answer: A) Returns true if subquery returns at least one row
29. What is the difference between UNION and UNION ALL?
A) UNION removes duplicates; UNION ALL includes duplicates
B) UNION ALL removes duplicates; UNION includes duplicates
C) Both are same
D) UNION is for tables; UNION ALL for views
Answer: A) UNION removes duplicates; UNION ALL includes duplicates
30. In which normal form is a table if it has no partial dependency?
A) 1NF
B) 2NF
C) 3NF
D) BCNF
Answer: B) 2NF
31. In which normal form is a table if it has no transitive dependency?
A) 1NF
B) 2NF
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 6/20
C) 3NF
D) 4NF
Answer: C) 3NF
32. Which key uniquely identifies a row in a table?
A) Foreign key
B) Primary key
C) Composite key
D) Candidate key
Answer: B) Primary key
33. Which SQL statement will show all indexes of a table (MySQL)?
A) SHOW INDEX FROM table_name;
B) LIST INDEXES table_name;
C) DESCRIBE INDEX table_name;
D) INDEX table_name;
Answer: A) SHOW INDEX FROM table_name;
34. Which command is used to remove a database?
A) REMOVE DATABASE db;
B) DELETE DATABASE db;
C) DROP DATABASE db;
D) TRUNCATE DATABASE db;
Answer: C) DROP DATABASE db;
35. Which SQL statement retrieves the first 10 rows?
A) SELECT * FROM table LIMIT 10;
B) SELECT TOP 10 * FROM table;
C) SELECT * FROM table FETCH FIRST 10 ROWS ONLY;
D) All of the above depending on DBMS
Answer: D) All of the above
36. What is the correct syntax for a CASE statement?
Answer:
sql
SELECT
CASE
WHEN salary > 5000 THEN 'High'
ELSE 'Low'
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 7/20
END
FROM Employee;
37. Which operator is used to test for NULL?
A) = NULL
B) == NULL
C) IS NULL
D) NULL?
Answer: C) IS NULL
38. Which of these commands creates a view?
A) CREATE VIEW view_name AS SELECT ...
B) CREATE TABLE view_name AS SELECT ...
C) NEW VIEW view_name SELECT ...
D) VIEW view_name;
Answer: A) CREATE VIEW view_name AS SELECT ...
39. Which query will find the second highest salary?
Answer:
sql
SELECT MAX(salary)
FROM Employee
WHERE salary < (SELECT MAX(salary) FROM Employee);
40. Which clause is used to rename a column temporarily?
A) CHANGE
B) RENAME
C) AS
D) MODIFY
Answer: C) AS
41. Which constraint is used to enforce a relationship between two tables?
A) FOREIGN KEY
B) UNIQUE
C) PRIMARY KEY
D) DEFAULT
Answer: A) FOREIGN KEY
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 8/20
42. Which function is used to find the largest value in a column?
A) GREATEST
B) MAX
C) BIGGEST
D) TOP
Answer: B) MAX
43. Which SQL keyword is used to remove a view?
A) REMOVE VIEW
B) DELETE VIEW
C) DROP VIEW
D) ALTER VIEW
Answer: C) DROP VIEW
44. What will be the output of:
sql
SELECT COUNT(DISTINCT dept) FROM Employee;
A) Count of employees
B) Count of unique departments
C) All departments
D) None
Answer: B) Count of unique departments
45. Which index type improves query performance on large tables?
A) Clustered index
B) Non-clustered index
C) Composite index
D) All of the above (depending on use)
Answer: D) All of the above
46. Which of these does NOT support transactions?
A) TRUNCATE
B) DELETE
C) UPDATE
D) INSERT
Answer: A) TRUNCATE
47. A table with only atomic values and no repeating groups is in:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 9/20
A) 1NF
B) 2NF
C) 3NF
D) 4NF
Answer: A) 1NF
48. Which clause is executed first in SQL query processing?
A) WHERE
B) SELECT
C) FROM
D) ORDER BY
Answer: C) FROM
49. Which SQL operator is used to combine the results of two queries including
duplicates?
A) UNION
B) UNION ALL
C) INTERSECT
D) JOIN
Answer: B) UNION ALL
50. Which SQL statement is used to backup a database?
A) BACKUP DATABASE db TO DISK = 'path'; (SQL Server)
B) mysqldump -u user -p db > backup.sql (MySQL)
Answer: A) BACKUP DATABASE (DB-specific)
These 50 MCQs cover almost all important SQL topics for campus placements.
Would you like me to:
1. Give 50 more advanced SQL query-based MCQs (purely query-oriented)?
2. Or prepare these 50 MCQs in PDF format for practice?
3. Or both?
1.
Here are 50 more advanced SQL query-based MCQs (medium to difficult) focusing mainly on
queries, joins, subqueries, CTEs, indexes, performance, and analytical functions.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 10/20
Advanced SQL Query-Based MCQs (Set 2 – 50 Questions)
1. Which query finds employees whose salary is more than the average salary?
sql
SELECT name FROM Employee
WHERE salary > (SELECT AVG(salary) FROM Employee);
What type of subquery is used here?
A) Correlated subquery
B) Scalar subquery
C) Inline view
D) Multi-row subquery
Answer: B) Scalar subquery
2. Which query will list departments having more than 5 employees?
A)
sql
SELECT dept FROM Employee GROUP BY dept HAVING COUNT(*) > 5;
B)
sql
SELECT dept FROM Employee WHERE COUNT(*) > 5;
C)
sql
SELECT dept FROM Employee WHERE COUNT(dept) > 5 GROUP BY dept;
D) None
Answer: A
3. To find duplicate rows based on a column in SQL:
A) Use DISTINCT
B) Use GROUP BY with HAVING COUNT(*) > 1
C) Use WHERE clause only
D) Use INTERSECT
Answer: B
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 11/20
4. Query to fetch the 3rd highest salary:
sql
SELECT DISTINCT salary FROM Employee e1
WHERE 2 = (
SELECT COUNT(DISTINCT salary) FROM Employee e2 WHERE e2.salary > e1.salary
);
Which approach is this?
A) LIMIT/TOP
B) Rank-based
C) Nested subquery with COUNT
D) Analytic function
Answer: C
5. Window functions can be used with which clause?
A) PARTITION BY
B) GROUP BY
C) JOIN
D) All of the above
Answer: D
6. Output of:
sql
SELECT department, RANK() OVER (PARTITION BY department ORDER BY salary DESC)
FROM Employee;
A) Department-wise top salary rank
B) Company-wide top salary rank
C) Department count
D) Error
Answer: A
7. Which query will return employee names who do not have a manager?
sql
SELECT name FROM Employee WHERE manager_id IS NULL;
This checks for:
A) Empty value
B) NULL value
C) 0
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 12/20
D) Missing column
Answer: B
8. A CTE (Common Table Expression) is defined using:
A) WITH clause
B) USING clause
C) TEMPORARY clause
D) DEFINE
Answer: A
9. To find all employees who earn a salary equal to the maximum salary:
sql
SELECT * FROM Employee WHERE salary = (SELECT MAX(salary) FROM Employee);
This query is an example of:
A) Join
B) Inline View
C) Scalar Subquery
D) Outer Join
Answer: C
10. What does ROW_NUMBER() return?
A) Random number
B) Sequential number for each row in a partition
C) Total number of rows
D) Unique key
Answer: B
11. Which query retrieves all employees who joined in the year 2022?
sql
SELECT * FROM Employee
WHERE YEAR(joining_date) = 2022;
Assuming DBMS supports YEAR().
Answer: This retrieves rows where joining_date year = 2022.
12. Query to delete duplicate rows keeping only one:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 13/20
sql
DELETE FROM Employee
WHERE id NOT IN (
SELECT MIN(id) FROM Employee GROUP BY name
);
Which concept is used here?
A) Self join
B) Grouping and subquery
C) Analytic function
D) Index scan
Answer: B
13. To combine rows from multiple queries but remove duplicates, use:
A) UNION
B) UNION ALL
C) INTERSECT
D) FULL OUTER JOIN
Answer: A
14. What is the output of:
sql
SELECT COUNT(*), SUM(salary) FROM Employee WHERE dept = 'IT';
A) Two columns: number of rows and sum of salaries in IT dept
B) Error
C) One column with both values
D) Only sum
Answer: A
15. Which query lists the employees who do not work in department table (no
matching dept_id)?
sql
SELECT e.* FROM Employee e
LEFT JOIN Department d ON e.dept_id = d.dept_id
WHERE d.dept_id IS NULL;
This is an example of:
A) Anti join
B) Cross join
C) Natural join
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 14/20
D) Inner join
Answer: A
16. When you use INNER JOIN, NULL values in join columns:
A) Are matched
B) Are ignored
C) Throw error
D) Replace with 0
Answer: B
17. Which of these is a valid analytic function?
A) SUM() OVER()
B) MAX() OVER()
C) RANK() OVER()
D) All of the above
Answer: D
18. The output of:
sql
SELECT dept, COUNT(*) FROM Employee
GROUP BY dept
ORDER BY COUNT(*) DESC
LIMIT 1;
A) Returns department with most employees
B) Returns all departments
C) Returns top 1 employee
D) Error
Answer: A
19. The result of:
sql
SELECT salary FROM Employee
ORDER BY salary DESC
LIMIT 1 OFFSET 1;
A) 1st highest salary
B) 2nd highest salary
C) 3rd highest salary
D) Error
Answer: B
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 15/20
20. Which query selects employees with salary between 5000 and 10000?
sql
SELECT * FROM Employee WHERE salary BETWEEN 5000 AND 10000;
21. Query to find employees whose name starts with 'S':
sql
SELECT * FROM Employee WHERE name LIKE 'S%';
22. Query to find employees whose name ends with 'n':
sql
SELECT * FROM Employee WHERE name LIKE '%n';
23. Query to find employees whose name has 'an' anywhere:
sql
SELECT * FROM Employee WHERE name LIKE '%an%';
24. EXPLAIN or EXPLAIN PLAN in SQL is used to:
A) Debug syntax errors
B) Show execution plan for performance
C) Run query faster
D) Generate indexes automatically
Answer: B
25. Which query creates a clustered index (SQL Server)?
sql
CREATE CLUSTERED INDEX idx_emp_salary ON Employee(salary);
26. Which SQL function returns the first non-null value?
A) IFNULL()
B) NVL()
C) COALESCE()
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 16/20
D) All of the above (depends on DBMS)
Answer: D
27. Which query uses EXISTS correctly?
sql
SELECT * FROM Employee e
WHERE EXISTS (SELECT 1 FROM Department d WHERE e.dept_id = d.dept_id);
28. Query to display employee with maximum salary per department (using window
function):
sql
SELECT * FROM (
SELECT e.*, RANK() OVER (PARTITION BY dept ORDER BY salary DESC) rnk
FROM Employee e
) t WHERE rnk = 1;
29. Which of the following is TRUE for CROSS JOIN?
A) Returns Cartesian product
B) Joins on common column
C) Filters NULL
D) Requires WHERE always
Answer: A
30. Which query creates a temporary table?
sql
CREATE TEMPORARY TABLE temp_table AS SELECT * FROM Employee;
31. Query to get top 10 salaries without duplicates:
sql
SELECT DISTINCT salary FROM Employee
ORDER BY salary DESC LIMIT 10;
32. Which query finds departments that have no employees?
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 17/20
sql
SELECT * FROM Department d
WHERE NOT EXISTS (
SELECT 1 FROM Employee e WHERE e.dept_id = d.dept_id
);
33. Which function can be used to concatenate strings?
A) CONCAT()
B) || (Oracle/Postgres)
C) + (SQL Server)
D) All of the above depending on DBMS
Answer: D
34. Which query calculates cumulative sum (running total)?
sql
SELECT name, SUM(salary) OVER (ORDER BY id) AS running_total FROM Employee;
35. When using GROUP BY, every column in SELECT must be:
A) Aggregate or grouped column
Answer: True
36. What does DELETE FROM table; do?
A) Deletes all rows but keeps table
Answer: True
37. Which keyword removes duplicate rows in SELECT output?
Answer: DISTINCT
38. Which function is used to return a random value?
A) RAND() (MySQL/SQL Server)
B) DBMS_RANDOM (Oracle)
39. Which query calculates percentage contribution of salary per department?
sql
SELECT dept, name,
salary * 100.0 / SUM(salary) OVER(PARTITION BY dept) AS percent
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 18/20
FROM Employee;
40. To restrict rows after grouping, we use:
Answer: HAVING
41. Query to pivot data (convert rows to columns) uses which clause in SQL Server?
Answer: PIVOT
42. Which keyword is used to fetch unique combinations of multiple columns?
Answer: SELECT DISTINCT col1, col2 FROM table;
43. Query to display first name in uppercase:
sql
SELECT UPPER(first_name) FROM Employee;
44. Query to display only first 3 characters of name:
sql
SELECT SUBSTRING(name,1,3) FROM Employee;
45. What is the default isolation level in SQL Server?
Answer: READ COMMITTED
46. Which query lists all tables in a database (MySQL)?
sql
SHOW TABLES;
47. Which SQL command is used to modify an existing table?
Answer: ALTER TABLE
48. Which type of join is equivalent to INTERSECT?
Answer: INNER JOIN on common conditions
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 19/20
49. When a table has a self-referencing foreign key, it is called?
Answer: Self-Join relationship
50. Which SQL clause allows creating recursive queries?
Answer: WITH RECURSIVE
These 50 advanced query-based MCQs focus on subqueries, joins, analytic functions, indexes, and
performance—commonly tested in placement coding rounds and written tests.
Would you like me to:
1. Combine both sets (100 questions) into a single PDF for practice?
2. Or provide practice SQL queries (hands-on coding exercises) next?
3. Or give answers with detailed explanations for each advanced question?
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 20/20