Skip to content
DevOps with Multi Cloud: new batch 25 Nov
novarynit: Training, Placement, Consulting

10 questions

SQL interview questions and answers

SQL questions that appear in almost every developer, tester and analyst interview: joins, keys, grouping and indexes.

What is the difference between WHERE and HAVING?
WHERE filters rows before grouping. HAVING filters groups after GROUP BY and can use aggregate functions such as COUNT or SUM.
Explain the types of joins.
INNER JOIN returns matching rows from both tables. LEFT JOIN returns all rows from the left table plus matches. RIGHT JOIN is the mirror. FULL JOIN returns all rows from both. CROSS JOIN returns every combination.
What is the difference between a primary key and a unique key?
Both enforce uniqueness. A table has one primary key and it cannot be NULL. A table can have several unique keys and they can allow NULL.
What is normalisation?
Organising tables to reduce repeated data and update problems. 1NF removes repeating groups, 2NF removes partial dependencies on a composite key, and 3NF removes dependencies between non-key columns.
What is the difference between DELETE, TRUNCATE and DROP?
DELETE removes chosen rows and can be rolled back. TRUNCATE removes all rows quickly and resets the table. DROP removes the table itself, structure included.
What is an index and when should you use one?
An index is a structure that lets the database find rows without scanning the whole table. Use it on columns used often in WHERE, JOIN and ORDER BY. It speeds reads and slows writes slightly.
How do you find the second highest salary?
One way: SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees). Another uses DENSE_RANK() OVER (ORDER BY salary DESC) and picks rank 2.
What is the difference between UNION and UNION ALL?
UNION combines results and removes duplicates. UNION ALL keeps duplicates and is faster because it skips that step.
What are window functions?
Functions such as ROW_NUMBER, RANK and SUM() OVER that calculate across a set of related rows without collapsing them into one row, unlike GROUP BY.
What are ACID properties?
Atomicity (all or nothing), Consistency (rules always hold), Isolation (transactions do not interfere) and Durability (committed data survives failures).

More topics

Next step

Practise these in a mock interview

Sit in a free demo class first. We will call you back in 5 minutes

  • See a live class before you join
  • Meet the trainer and review the syllabus
  • Get a batch and timing that fits you
  • Ask about EMI and placement support

Where to learn

  • Ameerpet, Hyderabad

    3rd Floor, Green House, Ameerpet, Hyderabad, Telangana

  • Live online

    Join the same class from anywhere, ask questions live and get the same project reviews.

Request your free demo

Takes 30 seconds. No payment needed.

+91

Free · no obligation

Book your free demo class

Leave your number and we will call you back.

  1. We will call you back in 5 minutes
  2. Attend a free demo class
  3. Join only if you like it