Playing as a guest? to earn XP and track your progress.
๐ Simple Queries in SQL Quiz
๐ Simple Queries in SQL
Which of the following is a correct String Literal in MySQL?
25
TRUE
'Computer Science'
2026-06-27
String literals must be enclosed in single quotes. 'Computer Science' is a string literal. 25 is a numeric literal, TRUE is a boolean literal, and 2026-06-27 without quotes is not valid as a date literal.
Which data type stores an exact decimal number and is recommended for storing salary or price fields?
FLOAT
INT
DECIMAL(m,d)
TEXT
DECIMAL(m,d) stores exact decimal numbers. FLOAT is approximate and can cause rounding errors. For financial data like salary or price, always use DECIMAL.
A column is defined as CHAR(10). A value 'Hi' is stored in it. How many characters of storage does it actually use?
2
5
10
Depends on the value
CHAR is fixed-length โ it always reserves exactly n characters of storage regardless of the actual data length, padding with spaces if needed. CHAR(10) always uses 10 characters.
What does a NULL value represent in MySQL?
The number zero
An empty string
The value 'NULL' stored as text
Missing, unknown, or inapplicable data
NULL represents missing, unknown, or inapplicable data. It is NOT the same as 0 (zero) or '' (empty string), which are actual known values.
Which of the following is a valid single-line comment in MySQL?
// This is a comment
/* This is a comment */
-- This is a comment
This is a comment
MySQL supports -- (double dash) and # (hash) for single-line comments, and /* */ for multi-line comments. // is used in languages like Java/C++ but not SQL.
Are SQL keywords like SELECT and WHERE case-sensitive?
Yes, they must always be in uppercase
Yes, they must always be in lowercase
No, SQL keywords are not case-sensitive
It depends on the operating system
SQL keywords (SELECT, WHERE, FROM, etc.) are NOT case-sensitive. SELECT, select, and Select all work identically. However, data values in string columns may be case-sensitive depending on the database collation.
What symbol is used at the end of every SQL statement to execute it?
. (period)
: (colon)
; (semicolon)
, (comma)
Every SQL statement must end with a semicolon (;). This tells MySQL that the statement is complete and ready to be executed.
Which SQL command lists all the databases available on the MySQL server?
LIST DATABASES;
SHOW DATABASES;
DISPLAY DATABASES;
SELECT DATABASES();
SHOW DATABASES; lists all databases available on the MySQL server. SHOW TABLES; lists all tables inside the currently selected database.
What does SELECT * FROM Employee; return?
Only the first row of the Employee table
Only the column names of the Employee table
All columns and all rows of the Employee table
The structure of the Employee table
The asterisk (*) is a wildcard meaning 'all columns'. SELECT * FROM Employee; retrieves every column and every row from the Employee table.
Based on the Employee table, what is the output of:
SELECT DISTINCT Dept FROM Employee;
Sales, IT, HR, IT, Sales, HR
Sales, IT, HR
IT, HR, Sales
Only IT (the most frequent)
DISTINCT removes duplicates. The Employee table has Sales (twice), IT (twice), HR (twice). After DISTINCT, only one of each appears: Sales, IT, HR.
What is the purpose of the DISTINCT keyword in a SELECT statement?
Sorts the result in ascending order
Removes duplicate rows from the query result
Selects only the first unique row
Filters rows using a condition
DISTINCT eliminates duplicate rows from the query result, ensuring each unique value or combination of values appears only once in the output.
What does SELECT ALL Dept FROM Employee; return compared to SELECT Dept FROM Employee;?
Only unique department names
Departments in alphabetical order
The exact same result โ all rows including duplicates
An error because ALL is not valid SQL
ALL is the default behaviour of SELECT โ it returns all rows including duplicates. SELECT ALL Dept and SELECT Dept produce identical output. ALL is rarely used explicitly.
Which command displays the structure of the Employee table (column names, data types, constraints) without showing any data?
SHOW Employee;
STRUCTURE Employee;
DESCRIBE Employee;
VIEW Employee;
DESCRIBE table_name; (or DESC table_name;) shows the table's structure including field names, data types, whether NULL is allowed, and key constraints โ without displaying the actual data rows.
What is the result of SELECT 17 % 5; in MySQL?
3.4
3
2
85
% is the modulus operator, which returns the remainder after division. 17 divided by 5 is 3 with a remainder of 2. So 17 % 5 = 2.
Which query correctly calculates annual salary (monthly salary multiplied by 12) for all employees?
SELECT Name, Salary + 12 FROM Employee;
SELECT Name, Salary * 12 FROM Employee;
SELECT Name, Salary, 12 FROM Employee;
SELECT Name, ANNUAL(Salary) FROM Employee;
Salary * 12 is a scalar expression that multiplies the Salary column value by 12 for every row, producing the annual salary.
What does a column alias do in a SELECT statement?
Permanently renames the column in the table
Creates a copy of the column in the database
Gives the column a temporary, readable name in the output only
Hides the column from the output
A column alias (using AS) gives a column a temporary display name in the query output only. It does NOT change the actual column name in the table.
Which query gives the output column the heading 'AnnualSalary' instead of 'Salary * 12'?
SELECT Name, Salary * 12 FROM Employee;
SELECT Name, Salary * 12 RENAME AnnualSalary FROM Employee;
SELECT Name, Salary * 12 AS AnnualSalary FROM Employee;
SELECT Name, AnnualSalary = Salary * 12 FROM Employee;
The AS keyword followed by the alias name creates a column alias. SELECT Name, Salary * 12 AS AnnualSalary renames the output column to 'AnnualSalary'.
Anjali Gupta has a NULL Salary. What will SELECT Salary * 12 FROM Employee WHERE Name = 'Anjali Gupta'; return?
0
12
NULL
An error
Any arithmetic operation involving NULL returns NULL. NULL * 12 = NULL because 'unknown times anything' is still unknown.
Which function replaces a NULL value with a specified default value?
ISNULL(col)
NULLIF(col, value)
IFNULL(col, default)
COALESCE()
IFNULL(col, default) returns the column value if it is not NULL, or returns the specified default value if the column is NULL. e.g., IFNULL(Salary, 0) returns 0 when Salary is NULL.
What is the purpose of the WHERE clause in a SELECT statement?
To sort the result in a specific order
To specify which columns to display
To filter rows based on a specified condition
To remove duplicate rows from the result
The WHERE clause filters records, returning only the rows that satisfy the specified Boolean condition. It controls WHICH rows are included in the result.
Based on the Employee table, how many rows does this query return?
SELECT Name FROM Employee WHERE Salary > 50000;
1
2
3
4
Employees with Salary > 50000 are Arjun Kumar (62000) and Rohan Das (71000). That is 2 rows. Anjali Gupta's NULL salary does not satisfy the condition.
Which operator checks if a value is NOT equal to another value in SQL?
=!
NOT =
!= or <>
~=
Both != and <> mean 'not equal to' in MySQL. Both are valid and produce the same result.
Which query returns employees who work in IT AND earn more than 60000?
SELECT * FROM Employee WHERE Dept = 'IT' OR Salary > 60000;
SELECT * FROM Employee WHERE Dept = 'IT' AND Salary > 60000;
SELECT * FROM Employee WHERE Dept = 'IT', Salary > 60000;
SELECT * FROM Employee WHERE Dept = 'IT' ALSO Salary > 60000;
AND requires BOTH conditions to be true simultaneously. OR would return employees who work in IT OR who earn more than 60000 (not necessarily both).
Based on the Employee table, what is the output of:
SELECT Name FROM Employee WHERE Dept = 'HR' OR Dept = 'Sales';
Only Sita Roy and Vikram Singh
Priya Sharma, Sita Roy, Anjali Gupta, Vikram Singh
Arjun Kumar and Rohan Das
All 6 employees
OR returns rows where AT LEAST ONE condition is true. HR employees are Sita Roy and Vikram Singh. Sales employees are Priya Sharma and Anjali Gupta. Together that is 4 employees.
The BETWEEN operator in SQL is:
Exclusive of both endpoints
Inclusive of both endpoints
Inclusive of the lower bound only
Inclusive of the upper bound only
BETWEEN is inclusive of BOTH endpoints. WHERE Salary BETWEEN 40000 AND 65000 is equivalent to WHERE Salary >= 40000 AND Salary <= 65000.
Based on the Employee table, how many rows does this query return?
SELECT Name FROM Employee WHERE Salary BETWEEN 40000 AND 65000;
2
3
4
5
Employees with Salary between 40000 and 65000 (inclusive): Priya Sharma (45000), Arjun Kumar (62000), Vikram Singh (41000). That is 3 rows. Anjali's NULL is excluded.
Which query is equivalent to: WHERE Dept = 'HR' OR Dept = 'Sales'?
WHERE Dept BETWEEN 'HR' AND 'Sales'
WHERE Dept LIKE ('HR', 'Sales')
WHERE Dept IN ('HR', 'Sales')
WHERE Dept = ('HR', 'Sales')
The IN operator checks if a value matches any value in a list. WHERE Dept IN ('HR', 'Sales') is exactly equivalent to WHERE Dept = 'HR' OR Dept = 'Sales'.
What does the % wildcard represent in a LIKE pattern?
Exactly one character
Any single digit
Any sequence of zero or more characters
A literal percent sign only
% matches any sequence of zero or more characters. For example, 'A%' matches any string starting with A, regardless of what follows.
What does the _ wildcard represent in a LIKE pattern?
Any sequence of characters
Exactly one character
A space character
Zero or more characters
_ (underscore) matches exactly ONE character. For example, '_ohan' matches 'Rohan' because _ matches 'R' and 'ohan' matches the rest.
Based on the Employee table, what does this query return?
SELECT Name FROM Employee WHERE Name LIKE 'A%';
Arjun Kumar only
Anjali Gupta only
Arjun Kumar and Anjali Gupta
No rows
'A%' matches any name starting with 'A'. Both Arjun Kumar and Anjali Gupta start with 'A', so both are returned.
Which query finds all employees whose name ends with the letter 'a'?
SELECT Name FROM Employee WHERE Name LIKE 'a';
SELECT Name FROM Employee WHERE Name LIKE '%a';
SELECT Name FROM Employee WHERE Name LIKE 'a%';
SELECT Name FROM Employee WHERE Name LIKE '_a';
'%a' means any sequence of characters followed by 'a' at the end. The % at the beginning matches everything before the last character 'a'.
Which query correctly finds employees whose Salary is NULL?
SELECT Name FROM Employee WHERE Salary = NULL;
SELECT Name FROM Employee WHERE Salary == NULL;
SELECT Name FROM Employee WHERE Salary IS NULL;
SELECT Name FROM Employee WHERE Salary = 'NULL';
NULL cannot be tested with = because NULL represents 'unknown'. You must use IS NULL. WHERE Salary = NULL always returns zero rows even when NULLs exist.
Based on the Employee table, how many rows does SELECT Name FROM Employee WHERE Salary IS NOT NULL; return?
4
5
6
0
Only Anjali Gupta (EmpId 105) has a NULL Salary. All other 5 employees have non-NULL salaries, so IS NOT NULL returns 5 rows.
In operator precedence, which logical operator is evaluated BEFORE the others?
OR
NOT
AND
OR and AND have equal precedence
The order is: Parentheses > Arithmetic > Comparison > NOT > AND > OR. AND is evaluated before OR, which means conditions joined by AND are grouped first.
Consider: WHERE Dept = 'IT' OR Dept = 'HR' AND Salary > 40000. Due to operator precedence, this is interpreted as:
(Dept = 'IT' OR Dept = 'HR') AND Salary > 40000
Dept = 'IT' OR (Dept = 'HR' AND Salary > 40000)
Dept = ('IT' OR 'HR') AND Salary > 40000
All conditions evaluated left to right equally
AND has higher precedence than OR, so it binds tighter. The condition is interpreted as: IT employees (any salary) OR (HR employees with Salary > 40000).
What does ORDER BY Salary DESC do?
Sorts employees in alphabetical order by name
Sorts from the lowest salary to the highest
Sorts from the highest salary to the lowest
Removes employees with duplicate salaries
DESC means descending order โ from the largest value to the smallest. ASC (ascending) is the default and goes from smallest to largest.
What is the default sort order when ORDER BY is used without ASC or DESC?
Descending (largest first)
Random order
The order rows were inserted
Ascending (smallest first)
ASC (ascending) is the default sort order in SQL. If you write ORDER BY Salary, it is the same as ORDER BY Salary ASC โ smallest values appear first.
What does UPPER('priya') return in MySQL?
'priya'
'Priya'
'PRIYA'
An error
UPPER() converts all characters in a string to uppercase. UPPER('priya') returns 'PRIYA'.
What does LENGTH('Priya') return?
4
5
6
10
LENGTH() returns the number of characters in a string. 'Priya' has 5 characters: P, r, i, y, a.
What does CONCAT('Hello, ', Name) do for the row where Name = 'Priya Sharma'?
Returns 'Hello'
Returns 'Hello, Priya Sharma'
Returns 'Priya SharmaHello'
Returns NULL
CONCAT() joins (concatenates) multiple strings together in the order given. CONCAT('Hello, ', 'Priya Sharma') produces 'Hello, Priya Sharma'.
What does SUBSTRING('Computer', 1, 4) return?
'Comp'
'pute'
'uter'
'Computer'
SUBSTRING(str, pos, len) extracts a substring starting at position pos (1-indexed) with length len. SUBSTRING('Computer', 1, 4) extracts 4 characters starting at position 1: 'Comp'.
What does ROUND(45.678, 2) return?
45.6
45.67
45.68
46.00
ROUND(num, d) rounds to d decimal places. The third decimal is 8 (โฅ5), so the second decimal is rounded up: 45.678 rounded to 2 places = 45.68.
What does TRUNCATE(45.678, 1) return?
45.7
45.6
46.0
45.68
TRUNCATE(num, d) cuts off digits after d decimal places WITHOUT rounding. TRUNCATE(45.678, 1) simply drops everything after the first decimal: 45.6.
Which function returns the current date only (without time) in MySQL?
NOW()
CURDATE()
CURTIME()
DATE()
CURDATE() returns the current date only (e.g., '2026-06-27'). NOW() returns current date AND time. CURTIME() returns current time only.
Which query displays the joining year for each employee from the Employee table?
SELECT Name, DOJ FROM Employee;
SELECT Name, YEAR(DOJ) FROM Employee;
SELECT Name, DATE(DOJ) FROM Employee;
SELECT Name, EXTRACT(DOJ) FROM Employee;
YEAR(date) extracts and returns the year portion from a DATE value. YEAR(DOJ) for Priya Sharma (DOJ: 2022-03-15) returns 2022.
What do aggregate functions like SUM, AVG, MAX, and MIN do with NULL values?
Treat NULL as 0 in the calculation
Return NULL as the final result if any NULL exists
Silently skip (ignore) NULL values
Throw an error when NULL is encountered
Aggregate functions (SUM, AVG, MAX, MIN, COUNT with column name) silently ignore NULL values. Anjali Gupta's NULL salary is not included in SUM, AVG, MAX, or MIN calculations.
Based on the Employee table, what does SELECT COUNT(*) FROM Employee; return?
4
5
6
It returns an error because of the NULL salary
COUNT(*) counts ALL rows regardless of NULL values. The Employee table has 6 rows, so COUNT(*) returns 6.
Based on the Employee table, what does SELECT COUNT(Salary) FROM Employee; return?
4
5
6
257000
COUNT(column_name) counts only non-NULL values in that column. Anjali Gupta's Salary is NULL, so it is excluded. 6 rows - 1 NULL = 5.
Based on the Employee table, what does SELECT SUM(Salary) FROM Employee; return?
(Salaries: 45000, 62000, 38000, 71000, NULL, 41000)
257000.00
214166.67
71000.00
NULL
SUM adds all non-NULL values: 45000 + 62000 + 38000 + 71000 + 41000 = 257000. The NULL value for Anjali Gupta is ignored.
Based on the Employee table, what does SELECT AVG(Salary) FROM Employee; return?
(Non-NULL salaries: 45000, 62000, 38000, 71000, 41000)
42833.33
51400.00
257000.00
38000.00
AVG ignores NULL values. Sum of 5 non-NULL salaries = 257000. AVG = 257000 / 5 = 51400.00. Note: AVG divides by the count of non-NULL values (5), not total rows (6).
Which query finds the name of the highest-paid employee?
SELECT Name FROM Employee WHERE Salary = MAXIMUM;
SELECT Name, MAX(Salary) FROM Employee;
SELECT Name FROM Employee WHERE Salary = (SELECT MAX(Salary) FROM Employee);
SELECT MAX(Name, Salary) FROM Employee;
MAX(Salary) alone returns 71000, not the name. To find the name of the employee with MAX salary, you use a subquery or WHERE with the MAX value. Option C uses a subquery correctly.
What is the correct SQL to display employee names in all uppercase letters?
SELECT NAME(upper) FROM Employee;
SELECT UPPER(Name) FROM Employee;
SELECT CAPS(Name) FROM Employee;
SELECT TO_UPPER(Name) FROM Employee;
UPPER(str) is the MySQL string function that converts a string to all uppercase characters. UPPER(Name) converts the Name value for each row to uppercase.
What does SELECT Name FROM Employee WHERE Name LIKE '_i%'; return from the Employee table?
Priya Sharma and Vikram Singh
Sita Roy and Vikram Singh
Sita Roy only
Vikram Singh only
'_i%' means: any one character, then 'i', then anything. Sita Roy: S(1 char) + i + ta Roy matches. Vikram Singh: V(1 char) + i + kram Singh matches. Priya has 'P' then 'r', not 'i'.
Which query displays employees from Delhi sorted by Name in ascending order?
SELECT * FROM Employee WHERE City = 'Delhi' SORT BY Name;
SELECT * FROM Employee ORDER BY Name WHERE City = 'Delhi';
SELECT * FROM Employee WHERE City = 'Delhi' ORDER BY Name ASC;
SELECT * FROM Employee WHERE City = 'Delhi' ORDER BY Name DESC;
WHERE must come before ORDER BY in SQL syntax. ASC is the correct keyword for ascending alphabetical order. SORT BY is not valid SQL.
What does SELECT POWER(2, 3) return?
6
8
9
5
POWER(m, n) raises m to the power n. POWER(2, 3) = 2ยณ = 2 ร 2 ร 2 = 8.
Which of the following correctly displays each employee's name along with the text 'works in' and their department as a single combined column?
SELECT Name + ' works in ' + Dept FROM Employee;
SELECT Name, 'works in', Dept FROM Employee;
SELECT CONCAT(Name, ' works in ', Dept) FROM Employee;
SELECT MERGE(Name, 'works in', Dept) FROM Employee;
CONCAT() joins multiple strings into one column. The + operator does not work for string concatenation in MySQL (it does arithmetic). CONCAT(Name, ' works in ', Dept) produces a single readable column.
Based on the Employee table, what does SELECT MIN(Salary) FROM Employee; return?
NULL
38000.00
41000.00
0
MIN() returns the smallest non-NULL value. The salaries (excluding NULL) are: 45000, 62000, 38000, 71000, 41000. The minimum is 38000 (Sita Roy).
Which SQL statement has a syntax error?
SELECT Name FROM Employee WHERE Dept = 'IT';
SELECT DISTINCT City FROM Employee;
SELECT Name FROM Employee WHERE Salary IS NULL;
SELECT Name FROM Employee WHERE Salary = NULL;
WHERE Salary = NULL is not a syntax error (MySQL accepts it) but it is a logical error โ it will always return zero rows because NULL cannot be compared using =. IS NULL must be used to find NULL values.
What is the output of SELECT ABS(-15); in MySQL?
-15
15
0
225
ABS() returns the absolute (positive) value of a number. ABS(-15) = 15.
A student writes SELECT Name FROM Employee WHERE City = 'delhi';. The Employee table stores cities as 'Delhi' (capital D). What will MySQL return by default?
An error โ incorrect case used
No rows โ MySQL is always case-sensitive for string values
The matching rows โ MySQL string comparisons are usually case-insensitive by default
All rows โ WHERE clause is ignored when case doesn't match
MySQL's default collation (utf8_general_ci, where 'ci' means case-insensitive) makes string comparisons case-insensitive. So 'delhi' matches 'Delhi' by default. This behaviour can change with different collation settings.