sql banner

SQL Multiple Choice Questions (MCQs) and Answers

Master SQL with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of SQL. Begin your placement preparation journey now!

Q211

Q211 Correct the syntax error in "UPDATE Products SET Price = Price * 1.1 WHERE Price < 100 OR Price > 200;"

A

Change '*' to '+' in 'Price * 1.1'

B

Remove 'OR Price > 200'

C

Replace 'WHERE' with 'AND'

D

No error

Q212

Q212 What is incorrect in "SELECT EmployeeID, Salary FROM Employees WHERE Salary BETWEEN 30000 AND 50000;"?

A

Change 'BETWEEN' to 'IN'

B

Replace 'AND' with 'OR'

C

Change 'Salary' to 'TotalSalary'

D

No error

Q213

Q213 In "SELECT Name FROM Employees WHERE NOT (Age < 30 AND Department = 'Sales');", identify the error.

A

Replace 'NOT' with 'NO'

B

Change 'AND' to 'OR'

C

Remove parentheses around condition

D

No error

Q214

Q214 Identify the mistake in
"SELECT * FROM Employees WHERE Department = 'HR' XOR Department = 'Finance';"

A

XOR operator

B

= 'HR'

C

= 'Finance'

D

No mistake, the statement is correct

Q215

Q215 What needs to be changed in "UPDATE Employees SET Salary *= 2 WHERE YearsOfExperience > 5;"?

A

Change '*=' to '=:='

B

Remove 'WHERE YearsOfExperience > 5'

C

Replace '2' with '2.0'

D

No error

Q216

Q216 What does the WHERE clause do in an SQL query?

A

Sorts the result set

B

Filters rows before grouping

C

Joins tables

D

Filters rows after grouping

Q217

Q217 What is the purpose of the ORDER BY clause in SQL?

A

Filters rows

B

Sorts the result set

C

Groups rows

D

Joins tables

Q218

Q218 In SQL, how does the GROUP BY clause function when combined with an aggregate function like SUM or COUNT?

A

It calculates the aggregate for the entire table

B

It groups rows based on unique values in a column and calculates the aggregate for each group

C

It filters the rows before aggregation

D

It sorts the result set

Q219

Q219 What is the main difference between WHERE and HAVING clauses in SQL?

A

WHERE filters rows before grouping, HAVING filters rows after grouping

B

HAVING filters rows before grouping, WHERE filters rows after grouping

C

No difference

D

WHERE is used with aggregate functions, HAVING is not

Q220

Q220 In an SQL query, what role does HAVING play without a GROUP BY clause?

A

It functions as a WHERE clause

B

It has no effect

C

It causes an error

D

It filters aggregated results

Q221

Q221 How does the ORDER BY clause treat NULL values by default?

A

It places them at the beginning of the result set

B

It places them at the end of the result set

C

It ignores them

D

It causes an error

Q222

Q222 What happens if you use a column in the SELECT statement that is not in the GROUP BY clause?

A

The query fails

B

The query succeeds, and the column shows arbitrary values

C

The query is automatically corrected

D

The column is ignored

Q223

Q223 Can the ORDER BY clause use column aliases defined in the SELECT statement?

A

Yes

B

No

C

Only if they are numerical

D

Only in subqueries

Q224

Q224 What is the effect of combining GROUP BY with ORDER BY in an SQL query?

A

GROUP BY overrides ORDER BY

B

ORDER BY overrides GROUP BY

C

They can be used together for organized grouping and sorting

D

They cannot be used together in the same query

Q225

Q225 In SQL, can the HAVING clause be used without an aggregate function?

A

Yes, it acts like a WHERE clause

B

No, it must be used with an aggregate function

C

Yes, but it has no effect

D

No, it causes an error

Q226

Q226 What is incorrect in "SELECT Name FROM Employees WHERE Department = 'Sales' ORDER BY Age;"?

A

Replace 'ORDER BY Age' with 'GROUP BY Age'

B

Change 'WHERE Department = 'Sales'' to 'WHERE Department IN ('Sales')'

C

Remove 'Name FROM'

D

No error

Q227

Q227 Identify the error in
"SELECT Department, COUNT(*) FROM Employees GROUP BY Salary;"

A

SELECT Department

B

COUNT(*)

C

GROUP BY Salary

D

No error

Q228

Q228 What needs to be corrected in
"SELECT AVG(Salary) AS AverageSalary FROM Employees HAVING AverageSalary > 50000;"?

A

SELECT AVG(Salary)

B

AS AverageSalary

C

FROM Employees

D

HAVING AverageSalary > 50000

Q229

Q229 Correct the syntax error in
"SELECT Name, Department, COUNT(*) FROM Employees WHERE Department = 'Sales' GROUP BY Department;"

A

SELECT Name

B

Department

C

COUNT(*)

D

WHERE Department = 'Sales'

Q230

Q230 In "SELECT Department, SUM(Salary) FROM Employees GROUP BY Department HAVING COUNT(*) > 5;", identify the error.

A

Replace 'SUM(Salary)' with 'AVG(Salary)'

B

Change 'GROUP BY' to 'ORDER BY'

C

Change 'COUNT(*)' to 'COUNT(Department)'

D

No error

Q231

Q231 What is incorrect in "SELECT * FROM Employees ORDER BY 3;"?

A

Change 'ORDER BY 3' to 'ORDER BY ID'

B

Replace '*' with 'EmployeeID, Name'

C

Add 'WHERE' clause before 'ORDER BY'

D

No error

Q232

Q232 Identify the mistake in
"SELECT Department, MAX(Salary) FROM Employees WHERE MAX(Salary) > 50000 GROUP BY Department;"

A

SELECT Department

B

MAX(Salary)

C

WHERE MAX(Salary) > 50000

D

GROUP BY Department

Q233

Q233 In "SELECT Department, COUNT(EmployeeID) FROM Employees GROUP BY Department HAVING COUNT(EmployeeID) > ALL (SELECT COUNT(EmployeeID) FROM Employees GROUP BY Department);" what needs correction?

A

Change 'COUNT(EmployeeID)' to 'SUM(EmployeeID)'

B

Replace 'GROUP BY' with 'ORDER BY'

C

Alter 'ALL' to 'ANY'

D

No error

Q234

Q234 Correct the error in
"SELECT Name FROM Employees WHERE Department IN (SELECT Department FROM Departments WHERE Location = 'New York') ORDER BY Name GROUP BY Department;"

A

WHERE Department IN

B

ORDER BY Name

C

GROUP BY Department

D

No error

Q235

Q235 What is wrong in
"SELECT Department, COUNT(*) AS TotalEmployees FROM Employees GROUP BY Department HAVING TotalEmployees > 5 ORDER BY TotalEmployees;"?

A

SELECT Department

B

COUNT(*) AS TotalEmployees

C

HAVING clause misuse

D

ORDER BY TotalEmployees

Q236

Q236 What is the main difference between UNION and UNION ALL in SQL?

A

UNION removes duplicates, UNION ALL does not

B

UNION ALL removes duplicates, UNION does not

C

No difference

D

UNION is faster than UNION ALL

Q237

Q237 What needs to be corrected in "SELECT Name FROM Employees UNION ALL SELECT Name FROM Managers;"?

A

Change 'UNION ALL' to 'UNION'

B

Replace first 'SELECT Name' with 'SELECT EmployeeName'

C

Add 'WHERE' clause to both SELECT statements

D

No error

Q238

Q238 Identify the error in
"SELECT Name, Department FROM Employees UNION SELECT Name FROM Managers;"

A

The UNION keyword

B

The number of columns in SELECT statements

C

The table names

D

No error

Q239

Q239 What does an INNER JOIN do in SQL?

A

Joins rows that satisfy a condition in either table

B

Joins all rows from both tables

C

Joins rows with matching values in both tables

D

Joins rows that do not match in either table

Q240

Q240 What is the main characteristic of a FULL OUTER JOIN?

A

It combines all records from both tables when there are no matches

B

It only joins rows with matching values in both tables

C

It excludes all unmatched rows

D

It joins rows that satisfy a condition in either table

ad vertical
ad