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.
Q1.Which SQL clause filters rows AFTER aggregation?
Easy- AWHERE
- BHAVING
- CGROUP BY
- DORDER BY
SQL Queries question 1 of 8+Show Answer & Explanation
Answer: B. HAVING
Explanation: HAVING applies to grouped results; WHERE is evaluated before grouping and cannot use aggregate functions.
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
SQL Queries question 2 of 8+Show Answer & Explanation
Answer: B. LEFT JOIN
Explanation: A LEFT (OUTER) JOIN preserves every left-table row, filling unmatched right-table columns with NULL.
Q3.Which command removes all rows from a table but cannot normally be rolled back?
Moderate- ADELETE
- BTRUNCATE
- CDROP
- DREMOVE
SQL Queries question 3 of 8+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.
Q4.What does SELECT COUNT(*) FROM table return when the table is empty?
Moderate- ANULL
- B0
- CAn error
- DNo rows
SQL Queries question 4 of 8+Show Answer & Explanation
Answer: B. 0
Explanation: COUNT(*) is an aggregate over the whole table and returns a single row containing 0.
Q5.Which operator tests for a value within a list?
Easy- ABETWEEN
- BIN
- CLIKE
- DEXISTS
SQL Queries question 5 of 8+Show Answer & Explanation
Answer: B. IN
Explanation: IN checks membership of a value list, e.g. WHERE city IN ('Pune', 'Mumbai').
Q6.To compare a column against NULL, you must use:
Moderate- A= NULL
- BIS NULL
- C== NULL
- DLIKE NULL
SQL Queries question 6 of 8+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.
Q7.Which set operator removes duplicate rows from the combined result?
Moderate- AUNION ALL
- BUNION
- CINTERSECT ALL
- DJOIN
SQL Queries question 7 of 8+Show Answer & Explanation
Answer: B. UNION
Explanation: UNION de-duplicates (and therefore sorts); UNION ALL simply concatenates and is faster when duplicates are acceptable.
Q8.A PRIMARY KEY constraint enforces that a column is:
Easy- AUnique only
- BNot null only
- CBoth unique and not null
- DIndexed but nullable
SQL Queries question 8 of 8+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 — 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.
