MyInternships.in

SQL Queries — Questions and Answers

SQL is the most interview-tested technical skill for freshers because almost every role touches data. The questions that separate candidates are not syntax recall but semantics: how NULL behaves, the difference between WHERE and HAVING, why DELETE and TRUNCATE are not interchangeable, and what each JOIN type actually returns when rows do not match.

8 solved questionsDatabaseFree · no signup

SQL Queries— Concepts, Formulas & Shortcuts

  • Logical execution order: FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY → LIMIT.
  • WHERE filters individual rows before grouping; HAVING filters groups after aggregation.
  • INNER JOIN keeps only matching rows; LEFT JOIN keeps all left rows with NULLs for missing right matches.
  • DELETE is DML, row-by-row, can be rolled back and fires triggers. TRUNCATE is DDL, deallocates pages and cannot be rolled back in most engines.
  • NULL is unknown: NULL = NULL is not true — use IS NULL. COUNT(column) skips NULLs but COUNT(*) does not.
  • UNION removes duplicates and sorts; UNION ALL keeps everything and is faster.

SQL Queries Practice Questions with Answers

Attempt each question first, then open the explanation. All 8 questions below are free to read and require no signup.

  1. Q1.Which SQL clause filters rows AFTER aggregation?

    Easy
    • AWHERE
    • BHAVING
    • CGROUP BY
    • DORDER BY
    +Show Answer & Explanation

    Answer: B. HAVING

    Explanation: HAVING applies to grouped results; WHERE is evaluated before grouping and cannot use aggregate functions.

    SQL Queries question 1 of 8
  2. Q2.Which JOIN returns all rows from the left table and matching rows from the right?

    Easy
    • AINNER JOIN
    • BLEFT JOIN
    • CRIGHT JOIN
    • DCROSS JOIN
    +Show Answer & Explanation

    Answer: B. LEFT JOIN

    Explanation: A LEFT (OUTER) JOIN preserves every left-table row, filling unmatched right-table columns with NULL.

    SQL Queries question 2 of 8
  3. Q3.Which command removes all rows from a table but cannot normally be rolled back?

    Moderate
    • ADELETE
    • BTRUNCATE
    • CDROP
    • DREMOVE
    +Show Answer & Explanation

    Answer: B. TRUNCATE

    Explanation: TRUNCATE is a DDL operation that deallocates data pages; it is far faster than DELETE but is not row-by-row logged.

    SQL Queries question 3 of 8
  4. Q4.What does SELECT COUNT(*) FROM table return when the table is empty?

    Moderate
    • ANULL
    • B0
    • CAn error
    • DNo rows
    +Show Answer & Explanation

    Answer: B. 0

    Explanation: COUNT(*) is an aggregate over the whole table and returns a single row containing 0.

    SQL Queries question 4 of 8
  5. Q5.Which operator tests for a value within a list?

    Easy
    • ABETWEEN
    • BIN
    • CLIKE
    • DEXISTS
    +Show Answer & Explanation

    Answer: B. IN

    Explanation: IN checks membership of a value list, e.g. WHERE city IN ('Pune', 'Mumbai').

    SQL Queries question 5 of 8
  6. Q6.To compare a column against NULL, you must use:

    Moderate
    • A= NULL
    • BIS NULL
    • C== NULL
    • DLIKE NULL
    +Show Answer & Explanation

    Answer: B. IS NULL

    Explanation: NULL means unknown, so equality comparisons return unknown rather than true. IS NULL is the only correct test.

    SQL Queries question 6 of 8
  7. Q7.Which set operator removes duplicate rows from the combined result?

    Moderate
    • AUNION ALL
    • BUNION
    • CINTERSECT ALL
    • DJOIN
    +Show Answer & Explanation

    Answer: B. UNION

    Explanation: UNION de-duplicates (and therefore sorts); UNION ALL simply concatenates and is faster when duplicates are acceptable.

    SQL Queries question 7 of 8
  8. Q8.A PRIMARY KEY constraint enforces that a column is:

    Easy
    • AUnique only
    • BNot null only
    • CBoth unique and not null
    • DIndexed but nullable
    +Show Answer & Explanation

    Answer: C. Both unique and not null

    Explanation: A primary key must uniquely identify each row, so it is both unique and non-nullable, and it creates an index automatically.

    SQL Queries question 8 of 8

SQL Queries — Frequently Asked Questions

What is the difference between WHERE and HAVING?+

WHERE filters rows before grouping and cannot reference aggregate functions. HAVING filters after GROUP BY and is where you put conditions like COUNT(*) > 5.

What is the difference between DELETE, TRUNCATE and DROP?+

DELETE removes selected rows and can be rolled back; TRUNCATE removes all rows quickly by deallocating pages and resets identity; DROP removes the entire table structure along with its data.

Cleared the aptitude round? Now grab the role.

Preparation only pays off when you apply. Thousands of internships and fresher jobs across India are live on MyInternships.in right now — free to apply, no consultancy fees.