DBMS and SQL Interview Questions with Answers

Database questions are asked in almost every fresher interview. These cover the essentials with short explanations.

  1. Q1. Which SQL clause filters rows before grouping?

    • A. WHERE
    • B. ORDER BY
    • C. GROUP BY
    • D. HAVING
    Show answer

    Answer: A. WHERE
    WHERE filters rows; HAVING filters groups after GROUP BY.

  2. Q2. Which SQL clause filters groups after aggregation?

    • A. LIMIT
    • B. HAVING
    • C. WHERE
    • D. DISTINCT
    Show answer

    Answer: B. HAVING
    e.g. GROUP BY dept HAVING COUNT(*) > 5.

  3. Q3. A primary key:

    • A. Must be text
    • B. Can have duplicate values
    • C. Links to another database
    • D. Uniquely identifies each row and cannot be NULL
    Show answer

    Answer: D. Uniquely identifies each row and cannot be NULL
    Each table has at most one primary key, which may span several columns.

  4. Q4. A foreign key:

    • A. Must be unique in its own table
    • B. Is always the first column
    • C. Encrypts data
    • D. References the primary key of another table
    Show answer

    Answer: D. References the primary key of another table
    It enforces referential integrity between tables.

  5. Q5. Which JOIN returns only rows with matching values in both tables?

    • A. CROSS JOIN
    • B. FULL OUTER JOIN
    • C. LEFT JOIN
    • D. INNER JOIN
    Show answer

    Answer: D. INNER JOIN
    LEFT JOIN also keeps unmatched rows from the left table.

  6. Q6. A LEFT JOIN returns:

    • A. All rows from the left table, with matches from the right (NULL if none)
    • B. The Cartesian product
    • C. Only matching rows
    • D. All rows from the right table
    Show answer

    Answer: A. All rows from the left table, with matches from the right (NULL if none)
    Unmatched right-side columns are filled with NULL.

  7. Q7. Which normal form removes partial dependency on part of a composite key?

    • A. 3NF
    • B. 1NF
    • C. BCNF only
    • D. 2NF
    Show answer

    Answer: D. 2NF
    1NF: atomic values. 2NF: no partial dependency. 3NF: no transitive dependency.

  8. Q8. What does ACID stand for in transactions?

    • A. Atomicity, Consistency, Isolation, Durability
    • B. Atomicity, Concurrency, Indexing, Durability
    • C. Accuracy, Consistency, Isolation, Distribution
    • D. Access, Control, Integrity, Data
    Show answer

    Answer: A. Atomicity, Consistency, Isolation, Durability
    These properties keep transactions reliable.

  9. Q9. Atomicity means a transaction:

    • A. Happens completely or not at all
    • B. Is stored on disk
    • C. Can be seen by all users immediately
    • D. Runs very fast
    Show answer

    Answer: A. Happens completely or not at all
    If any part fails, the whole transaction is rolled back.

  10. Q10. Which SQL statement removes all rows but keeps the table structure, and usually can't be rolled back in MySQL?

    • A. REMOVE
    • B. TRUNCATE
    • C. DROP
    • D. DELETE without WHERE
    Show answer

    Answer: B. TRUNCATE
    DROP removes the table itself; DELETE removes rows one by one and can be rolled back.

  11. Q11. Which function counts rows in SQL?

    • A. NUM()
    • B. SUM()
    • C. TOTAL()
    • D. COUNT()
    Show answer

    Answer: D. COUNT()
    COUNT(*) counts all rows; COUNT(col) ignores NULLs.

  12. Q12. An index in a database mainly:

    • A. Removes duplicates
    • B. Speeds up searches at the cost of extra storage and slower writes
    • C. Backs up data
    • D. Encrypts the table
    Show answer

    Answer: B. Speeds up searches at the cost of extra storage and slower writes
    Like a book's index, it avoids scanning every row.

  13. Q13. Which query finds the second highest salary (most portable answer)?

    • A. SELECT MAX(salary) FROM emp WHERE salary < (SELECT MAX(salary) FROM emp)
    • B. SELECT MAX(salary) - 1 FROM emp
    • C. SELECT SECOND(salary) FROM emp
    • D. SELECT salary FROM emp ORDER BY salary LIMIT 2
    Show answer

    Answer: A. SELECT MAX(salary) FROM emp WHERE salary < (SELECT MAX(salary) FROM emp)
    A classic interview query; window functions like DENSE_RANK also work.

  14. Q14. What does DISTINCT do in SELECT DISTINCT city FROM students?

    • A. Removes NULL cities only
    • B. Returns each city only once
    • C. Sorts the cities
    • D. Counts the cities
    Show answer

    Answer: B. Returns each city only once
    It removes duplicate rows from the result.

  15. Q15. Which is a NoSQL database?

    • A. Oracle Database
    • B. PostgreSQL
    • C. MongoDB
    • D. MySQL
    Show answer

    Answer: C. MongoDB
    MongoDB stores JSON-like documents instead of tables.

  16. Q16. What is a deadlock in databases?

    • A. Two transactions each waiting for a lock the other holds
    • B. A slow query
    • C. A deleted table
    • D. A full disk
    Show answer

    Answer: A. Two transactions each waiting for a lock the other holds
    The database detects it and aborts one of the transactions.

  17. Q17. Which SQL keyword sorts results?

    • A. ORDER BY
    • B. GROUP BY
    • C. SORT BY
    • D. ARRANGE
    Show answer

    Answer: A. ORDER BY
    ORDER BY col ASC/DESC.

  18. Q18. A view in SQL is:

    • A. An index
    • B. A saved query that behaves like a virtual table
    • C. A backup
    • D. A copy of a table
    Show answer

    Answer: B. A saved query that behaves like a virtual table
    It doesn't store data itself (unless it's a materialized view).

  19. Q19. Which isolation problem occurs when a transaction reads data another transaction hasn't committed yet?

    • A. Deadlock
    • B. Phantom read
    • C. Lost update
    • D. Dirty read
    Show answer

    Answer: D. Dirty read
    Prevented by READ COMMITTED and stronger isolation levels.

  20. Q20. What does GROUP BY department with COUNT(*) return?

    • A. Sorted department names
    • B. The total number of departments only
    • C. Departments with no employees
    • D. The number of rows in each department
    Show answer

    Answer: D. The number of rows in each department
    One result row per group.

  21. Q21. Which constraint ensures a column never contains NULL?

    • A. NOT NULL
    • B. CHECK
    • C. UNIQUE
    • D. DEFAULT
    Show answer

    Answer: A. NOT NULL
    UNIQUE still allows NULLs in most databases.

  22. Q22. What is denormalization?

    • A. Removing all keys
    • B. Deleting old data
    • C. Adding redundancy on purpose to speed up reads
    • D. Splitting tables further
    Show answer

    Answer: C. Adding redundancy on purpose to speed up reads
    Common in reporting and read-heavy systems.

  23. Q23. Which SQL pattern matches names starting with 'A'?

    • A. name LIKE '%A'
    • B. name = 'A*'
    • C. name LIKE 'A%'
    • D. name STARTS 'A'
    Show answer

    Answer: C. name LIKE 'A%'
    % matches any sequence of characters; _ matches one.

  24. Q24. UNION vs UNION ALL:

    • A. UNION removes duplicates; UNION ALL keeps them
    • B. They are identical
    • C. UNION ALL removes duplicates
    • D. UNION only works on numbers
    Show answer

    Answer: A. UNION removes duplicates; UNION ALL keeps them
    UNION ALL is faster because it skips the duplicate check.

  25. Q25. A composite key is:

    • A. An encrypted key
    • B. A key made of two or more columns
    • C. A key with text and numbers
    • D. A foreign key to itself
    Show answer

    Answer: B. A key made of two or more columns
    e.g. (student_id, course_id) in an enrolments table.

  26. Q26. What is a primary key?

    • A. A column that links to another table
    • B. A column (or set) that uniquely identifies each row and can't be NULL
    • C. The first column of a table
    • D. Any column with numbers
    Show answer

    Answer: B. A column (or set) that uniquely identifies each row and can't be NULL
    Each table has one primary key.

  27. Q27. What is a foreign key?

    • A. A key used for encryption
    • B. A key from another database
    • C. A duplicate primary key
    • D. A column that refers to the primary key of another table
    Show answer

    Answer: D. A column that refers to the primary key of another table
    It enforces referential integrity between tables.

  28. Q28. What is a candidate key?

    • A. Any minimal set of columns that could serve as the primary key
    • B. The second column of a table
    • C. A key waiting to be deleted
    • D. A foreign key in another table
    Show answer

    Answer: A. Any minimal set of columns that could serve as the primary key
    One candidate key is chosen as the primary key; the others are alternate keys.

  29. Q29. What is a composite key?

    • A. A key that is also a foreign key
    • B. An encrypted key
    • C. A key with a numeric type
    • D. A key made of two or more columns
    Show answer

    Answer: D. A key made of two or more columns
    e.g. (student_id, course_id) in an enrolment table.

  30. Q30. What does normalization aim to reduce?

    • A. Query speed
    • B. The number of users
    • C. Data redundancy and update anomalies
    • D. The number of tables
    Show answer

    Answer: C. Data redundancy and update anomalies
    Split data so each fact is stored once.

  31. Q31. A table is in 1NF when:

    • A. It has no foreign keys
    • B. It has a primary key of one column
    • C. It has fewer than 10 columns
    • D. Every column holds atomic (single) values
    Show answer

    Answer: D. Every column holds atomic (single) values
    No lists or repeating groups inside a cell.

  32. Q32. 2NF removes which kind of dependency?

    • A. Multivalued dependency
    • B. Transitive dependency
    • C. Partial dependency on part of a composite key
    • D. Join dependency
    Show answer

    Answer: C. Partial dependency on part of a composite key
    Every non-key column must depend on the whole key.

  33. Q33. 3NF removes which kind of dependency?

    • A. Partial dependency
    • B. Transitive dependency (non-key → non-key)
    • C. Any dependency on the key
    • D. Foreign keys
    Show answer

    Answer: B. Transitive dependency (non-key → non-key)
    e.g. storing city and pincode where pincode determines city.

  34. Q34. What is BCNF?

    • A. A backup format
    • B. A type of index
    • C. A SQL command
    • D. A stricter 3NF where every determinant is a candidate key
    Show answer

    Answer: D. A stricter 3NF where every determinant is a candidate key
    Boyce-Codd Normal Form.

  35. Q35. What does ACID stand for?

    • A. Accuracy, Concurrency, Index, Design
    • B. Atomicity, Consistency, Isolation, Durability
    • C. Access, Control, Integrity, Data
    • D. Atomic, Cached, Indexed, Distributed
    Show answer

    Answer: B. Atomicity, Consistency, Isolation, Durability
    The guarantees of a reliable transaction.

  36. Q36. What does atomicity guarantee?

    • A. Data is saved to disk
    • B. A transaction happens completely or not at all
    • C. Data types are correct
    • D. Transactions run one at a time
    Show answer

    Answer: B. A transaction happens completely or not at all
    If a bank transfer fails halfway, both updates are rolled back.

  37. Q37. What does durability guarantee?

    • A. Only one user can connect
    • B. Committed changes survive crashes
    • C. Data can't be deleted
    • D. Queries run fast
    Show answer

    Answer: B. Committed changes survive crashes
    Usually through write-ahead logs.

  38. Q38. What does isolation guarantee?

    • A. Concurrent transactions don't see each other's partial work
    • B. Each user has a separate database
    • C. Data is encrypted
    • D. Tables are stored separately
    Show answer

    Answer: A. Concurrent transactions don't see each other's partial work
    Isolation levels trade safety for speed.

  39. Q39. Which SQL command removes all rows but keeps the table structure, and usually can't be rolled back?

    • A. REMOVE
    • B. TRUNCATE
    • C. DELETE
    • D. DROP
    Show answer

    Answer: B. TRUNCATE
    DELETE removes rows one by one (can use WHERE); DROP removes the whole table.

  40. Q40. Which SQL command removes the table itself?

    • A. DELETE FROM
    • B. TRUNCATE
    • C. ALTER TABLE
    • D. DROP TABLE
    Show answer

    Answer: D. DROP TABLE
    Structure and data are both gone.

  41. Q41. Which clause filters groups after GROUP BY?

    • A. LIMIT
    • B. HAVING
    • C. ORDER BY
    • D. WHERE
    Show answer

    Answer: B. HAVING
    WHERE filters rows before grouping; HAVING filters groups after.

  42. Q42. What is the correct order of clauses in a SELECT?

    • A. SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY
    • B. SELECT, GROUP BY, FROM, WHERE
    • C. SELECT, WHERE, FROM, ORDER BY, GROUP BY
    • D. FROM, SELECT, HAVING, WHERE
    Show answer

    Answer: A. SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY
    Logically, FROM and WHERE run first and ORDER BY last.

  43. Q43. Which JOIN returns only rows with matching values in both tables?

    • A. INNER JOIN
    • B. FULL OUTER JOIN
    • C. CROSS JOIN
    • D. LEFT JOIN
    Show answer

    Answer: A. INNER JOIN
    Unmatched rows are dropped.

  44. Q44. Which JOIN returns all rows of the left table, with NULLs where the right table has no match?

    • A. RIGHT JOIN
    • B. LEFT JOIN
    • C. INNER JOIN
    • D. SELF JOIN
    Show answer

    Answer: B. LEFT JOIN
    Also called LEFT OUTER JOIN.

  45. Q45. What does a CROSS JOIN of a 3-row and a 4-row table return?

    • A. 7 rows
    • B. 3 rows
    • C. 12 rows
    • D. 4 rows
    Show answer

    Answer: C. 12 rows
    Every row paired with every row (Cartesian product).

  46. Q46. What is a self join?

    • A. A join inside a view
    • B. A join without a condition
    • C. A table joined with itself
    • D. A join on primary keys only
    Show answer

    Answer: C. A table joined with itself
    e.g. matching employees with their managers in the same table.

  47. Q47. What does an index do?

    • A. Prevents duplicate tables
    • B. Encrypts a column
    • C. Speeds up searches on a column at the cost of extra storage and slower writes
    • D. Sorts the table permanently
    Show answer

    Answer: C. Speeds up searches on a column at the cost of extra storage and slower writes
    Most databases use B-tree indexes.

  48. Q48. What is the difference between a clustered and a non-clustered index?

    • A. A clustered index can't be on a primary key
    • B. They are the same
    • C. A clustered index sets the physical order of rows; a non-clustered index is a separate structure
    • D. A non-clustered index sorts the table
    Show answer

    Answer: C. A clustered index sets the physical order of rows; a non-clustered index is a separate structure
    A table can have only one clustered index.

  49. Q49. What is a view?

    • A. A copy of a table
    • B. A saved query that behaves like a virtual table
    • C. A backup
    • D. A type of index
    Show answer

    Answer: B. A saved query that behaves like a virtual table
    Views simplify complex queries and can restrict which columns users see.

  50. Q50. What does the UNIQUE constraint ensure?

    • A. No two rows have the same value in that column
    • B. The column is the primary key
    • C. The column can't be NULL
    • D. The column is indexed for speed only
    Show answer

    Answer: A. No two rows have the same value in that column
    Unlike a primary key, UNIQUE columns may allow NULL.

  51. Q51. What is the difference between UNION and UNION ALL?

    • A. UNION ALL removes duplicates
    • B. There is no difference
    • C. UNION joins columns side by side
    • D. UNION removes duplicates; UNION ALL keeps them
    Show answer

    Answer: D. UNION removes duplicates; UNION ALL keeps them
    UNION ALL is faster because it doesn't de-duplicate.

  52. Q52. Which statement is DDL (Data Definition Language)?

    • A. SELECT
    • B. INSERT
    • C. UPDATE
    • D. CREATE TABLE
    Show answer

    Answer: D. CREATE TABLE
    DDL: CREATE, ALTER, DROP. DML: INSERT, UPDATE, DELETE.

  53. Q53. Which commands are TCL (Transaction Control Language)?

    • A. SELECT and INSERT
    • B. CREATE and DROP
    • C. GRANT and REVOKE
    • D. COMMIT and ROLLBACK
    Show answer

    Answer: D. COMMIT and ROLLBACK
    GRANT and REVOKE are DCL.

  54. Q54. What does COUNT(column) ignore?

    • A. Negative values
    • B. Zero values
    • C. NULL values
    • D. Duplicate values
    Show answer

    Answer: C. NULL values
    COUNT(*) counts every row.

  55. Q55. How do you check for NULL in SQL?

    • A. column = NULL
    • B. column IS NULL
    • C. ISNULL = column
    • D. column == NULL
    Show answer

    Answer: B. column IS NULL
    Any comparison with NULL using = gives unknown, not true.

  56. Q56. What is a stored procedure?

    • A. A user account
    • B. A backup schedule
    • C. A type of table
    • D. A saved set of SQL statements that runs on the database server
    Show answer

    Answer: D. A saved set of SQL statements that runs on the database server
    Reduces network trips and centralises logic.

  57. Q57. What is a trigger?

    • A. A scheduled backup
    • B. SQL that runs automatically on INSERT, UPDATE or DELETE
    • C. A user permission
    • D. An index type
    Show answer

    Answer: B. SQL that runs automatically on INSERT, UPDATE or DELETE
    e.g. writing to an audit log whenever salaries change.

  58. Q58. What is a deadlock in databases?

    • A. A full disk
    • B. Two transactions each waiting for a lock the other holds
    • C. A query that returns no rows
    • D. A dropped table
    Show answer

    Answer: B. Two transactions each waiting for a lock the other holds
    The database aborts one transaction to break it.

  59. Q59. What is denormalization?

    • A. Converting tables to 1NF
    • B. Adding redundancy on purpose to make reads faster
    • C. Removing all keys
    • D. Deleting duplicate rows
    Show answer

    Answer: B. Adding redundancy on purpose to make reads faster
    Common in reporting and analytics databases.

  60. Q60. What is the difference between SQL and NoSQL databases?

    • A. NoSQL can't store data
    • B. SQL uses fixed schemas and tables; NoSQL uses flexible models like documents or key-value
    • C. SQL databases can't scale at all
    • D. They are the same
    Show answer

    Answer: B. SQL uses fixed schemas and tables; NoSQL uses flexible models like documents or key-value
    MongoDB is a document store; Redis is key-value.

  61. Q61. Which aggregate function returns the number of rows?

    • A. TOTAL
    • B. NUMBER
    • C. COUNT
    • D. SUM
    Show answer

    Answer: C. COUNT
    SELECT COUNT(*) FROM students;

  62. Q62. Which keyword removes duplicate rows from a result?

    • A. DIFFERENT
    • B. SINGLE
    • C. UNIQUE
    • D. DISTINCT
    Show answer

    Answer: D. DISTINCT
    SELECT DISTINCT city FROM students;

  63. Q63. Which operator matches a pattern like names starting with 'A'?

    • A. LIKE 'A%'
    • B. = 'A*'
    • C. IN ('A')
    • D. MATCH 'A'
    Show answer

    Answer: A. LIKE 'A%'
    % matches any number of characters; _ matches exactly one.

  64. Q64. What does ORDER BY salary DESC do?

    • A. Sorts rows from highest to lowest salary
    • B. Removes duplicate salaries
    • C. Groups by salary
    • D. Sorts from lowest to highest
    Show answer

    Answer: A. Sorts rows from highest to lowest salary
    ASC is the default.

  65. Q65. What is an entity in an ER diagram?

    • A. A column
    • B. A real-world object stored as a table, like Student
    • C. A relationship between tables
    • D. A SQL query
    Show answer

    Answer: B. A real-world object stored as a table, like Student
    Attributes become columns; relationships may become foreign keys.

  66. Q66. How is a many-to-many relationship stored in a relational database?

    • A. It can't be stored
    • B. With a junction table holding both foreign keys
    • C. With one foreign key in either table
    • D. In a single column as a list
    Show answer

    Answer: B. With a junction table holding both foreign keys
    e.g. enrolments(student_id, course_id).

  67. Q67. What does this query return?

    Table emp(id, name, dept, salary, manager_id):
    1 Asha IT 60000 NULL
    2 Bala IT 45000 1
    3 Charu HR 40000 1
    4 Dev HR 40000 3
    5 Esha Sales 35000 1
    6 Farid IT NULL 2
    
    SELECT COUNT(salary) FROM emp;
    • A. 6
    • B. 5
    • C. 3
    • D. 4
    Show answer

    Answer: B. 5
    COUNT(salary) skips Farid's NULL salary.

  68. Q68. What does this query return?

    Table emp(id, name, dept, salary, manager_id):
    1 Asha IT 60000 NULL
    2 Bala IT 45000 1
    3 Charu HR 40000 1
    4 Dev HR 40000 3
    5 Esha Sales 35000 1
    6 Farid IT NULL 2
    
    SELECT COUNT(*) FROM emp;
    • A. 6
    • B. 5
    • C. 4
    • D. 0
    Show answer

    Answer: A. 6
    COUNT(*) counts every row, including NULLs.

  69. Q69. What does this query return?

    Table emp(id, name, dept, salary, manager_id):
    1 Asha IT 60000 NULL
    2 Bala IT 45000 1
    3 Charu HR 40000 1
    4 Dev HR 40000 3
    5 Esha Sales 35000 1
    6 Farid IT NULL 2
    
    SELECT COUNT(DISTINCT dept) FROM emp;
    • A. 2
    • B. 4
    • C. 3
    • D. 5
    Show answer

    Answer: C. 3
    The departments are IT, HR and Sales.

  70. Q70. What does this query return?

    Table emp(id, name, dept, salary, manager_id):
    1 Asha IT 60000 NULL
    2 Bala IT 45000 1
    3 Charu HR 40000 1
    4 Dev HR 40000 3
    5 Esha Sales 35000 1
    6 Farid IT NULL 2
    
    SELECT dept FROM emp GROUP BY dept HAVING COUNT(*) > 2;
    • A. HR
    • B. IT
    • C. IT HR
    • D. Sales
    Show answer

    Answer: B. IT
    Only IT has more than 2 employees (Asha, Bala, Farid).

  71. Q71. What does this query return?

    Table emp(id, name, dept, salary, manager_id):
    1 Asha IT 60000 NULL
    2 Bala IT 45000 1
    3 Charu HR 40000 1
    4 Dev HR 40000 3
    5 Esha Sales 35000 1
    6 Farid IT NULL 2
    
    SELECT MAX(salary) FROM emp WHERE salary < (SELECT MAX(salary) FROM emp);
    • A. 40000
    • B. 35000
    • C. 60000
    • D. 45000
    Show answer

    Answer: D. 45000
    Second-highest distinct salary: the max below 60000.

  72. Q72. What does this query return?

    Table emp(id, name, dept, salary, manager_id):
    1 Asha IT 60000 NULL
    2 Bala IT 45000 1
    3 Charu HR 40000 1
    4 Dev HR 40000 3
    5 Esha Sales 35000 1
    6 Farid IT NULL 2
    
    SELECT name FROM emp WHERE salary IS NULL;
    • A. Bala
    • B. Nothing
    • C. Farid
    • D. Asha
    Show answer

    Answer: C. Farid
    IS NULL finds the missing salary; = NULL would match nothing.

  73. Q73. What does this query return?

    Table emp(id, name, dept, salary, manager_id):
    1 Asha IT 60000 NULL
    2 Bala IT 45000 1
    3 Charu HR 40000 1
    4 Dev HR 40000 3
    5 Esha Sales 35000 1
    6 Farid IT NULL 2
    
    SELECT AVG(salary) FROM emp WHERE dept = 'HR';
    • A. 0
    • B. 80000
    • C. 40000
    • D. 45000
    Show answer

    Answer: C. 40000
    HR has two employees, both earning 40000; AVG is 40000.

  74. Q74. What does this query return?

    Table emp(id, name, dept, salary, manager_id):
    1 Asha IT 60000 NULL
    2 Bala IT 45000 1
    3 Charu HR 40000 1
    4 Dev HR 40000 3
    5 Esha Sales 35000 1
    6 Farid IT NULL 2
    
    SELECT m.name FROM emp e JOIN emp m ON e.manager_id = m.id
    GROUP BY m.name HAVING COUNT(*) = 3;
    • A. Asha
    • B. Bala
    • C. Charu
    • D. Esha
    Show answer

    Answer: A. Asha
    Asha (id 1) is the manager of Bala, Charu and Esha: three reports.

  75. Q75. What does this query return?

    Table emp(id, name, dept, salary, manager_id):
    1 Asha IT 60000 NULL
    2 Bala IT 45000 1
    3 Charu HR 40000 1
    4 Dev HR 40000 3
    5 Esha Sales 35000 1
    6 Farid IT NULL 2
    
    SELECT SUM(salary) FROM emp WHERE dept = 'IT';
    • A. NULL
    • B. 45000
    • C. 105000
    • D. 60000
    Show answer

    Answer: C. 105000
    SUM ignores Farid's NULL: 60000 + 45000.

  76. Q76. What does this query return?

    Table emp(id, name, dept, salary, manager_id):
    1 Asha IT 60000 NULL
    2 Bala IT 45000 1
    3 Charu HR 40000 1
    4 Dev HR 40000 3
    5 Esha Sales 35000 1
    6 Farid IT NULL 2
    
    SELECT name FROM emp WHERE name LIKE '%a' AND dept = 'Sales';
    • A. Esha
    • B. Charu
    • C. Asha
    • D. Dev
    Show answer

    Answer: A. Esha
    Asha and Esha end in 'a'; of those, only Esha is in Sales.

  77. Q77. What does this query return?

    Table emp(id, name, dept, salary, manager_id):
    1 Asha IT 60000 NULL
    2 Bala IT 45000 1
    3 Charu HR 40000 1
    4 Dev HR 40000 3
    5 Esha Sales 35000 1
    6 Farid IT NULL 2
    
    SELECT COUNT(*) FROM emp WHERE salary = 40000;
    • A. 3
    • B. 0
    • C. 2
    • D. 1
    Show answer

    Answer: C. 2
    Charu and Dev earn exactly 40000.

  78. Q78. What does this query return?

    Table emp(id, name, dept, salary, manager_id):
    1 Asha IT 60000 NULL
    2 Bala IT 45000 1
    3 Charu HR 40000 1
    4 Dev HR 40000 3
    5 Esha Sales 35000 1
    6 Farid IT NULL 2
    
    SELECT name FROM emp WHERE salary IS NOT NULL
    ORDER BY salary DESC LIMIT 2;
    • A. Asha Bala Farid
    • B. Asha
    • C. Asha Bala
    • D. Bala Asha
    Show answer

    Answer: C. Asha Bala
    Sorted by salary descending, the top two are 60000 (Asha) and 45000 (Bala).

  79. Q79. What does this query return?

    Table emp(id, name, dept, salary, manager_id):
    1 Asha IT 60000 NULL
    2 Bala IT 45000 1
    3 Charu HR 40000 1
    4 Dev HR 40000 3
    5 Esha Sales 35000 1
    6 Farid IT NULL 2
    
    SELECT COUNT(*) FROM emp WHERE manager_id IS NULL;
    • A. 1
    • B. 0
    • C. 2
    • D. 6
    Show answer

    Answer: A. 1
    Only Asha has no manager (manager_id IS NULL).

  80. Q80. What does this query return?

    Table emp(id, name, dept, salary, manager_id):
    1 Asha IT 60000 NULL
    2 Bala IT 45000 1
    3 Charu HR 40000 1
    4 Dev HR 40000 3
    5 Esha Sales 35000 1
    6 Farid IT NULL 2
    
    SELECT dept FROM emp GROUP BY dept
    ORDER BY SUM(salary) ASC LIMIT 1;
    • A. HR
    • B. Sales
    • C. Nothing
    • D. IT
    Show answer

    Answer: B. Sales
    Sales has the lowest total: 35000.

Practised these? Now prove it.

Take a timed mock test with new questions every attempt, earn a verified certificate at 70%+, and get noticed by employers.

Start a mock test