SQL is asked in almost every data, backend and analyst interview. These fresher questions cover querying, joins, aggregation and indexing with clear answers and a practice path.
WHERE filters rows before grouping and cannot use aggregate functions. HAVING filters groups after GROUP BY and can use aggregates like COUNT or SUM. Example: WHERE country = "IN" then GROUP BY city HAVING COUNT(*) > 10.
INNER JOIN returns matching rows in both tables. LEFT JOIN returns all left rows plus matches (NULLs where none). RIGHT JOIN is the mirror. FULL OUTER JOIN returns all rows from both. CROSS JOIN returns the Cartesian product.
DELETE removes rows (optionally with WHERE) and is logged/rollback-able. TRUNCATE quickly removes all rows, cannot use WHERE, and resets identity. DROP removes the entire table (structure and data).
A primary key uniquely identifies each row in a table and cannot be NULL. A foreign key is a column that references a primary key in another table, enforcing referential integrity between related tables.
An index is a data structure (usually a B-tree) that speeds up lookups and sorting on a column, at the cost of extra storage and slower writes. Index columns used in WHERE, JOIN and ORDER BY; avoid over-indexing.
GROUP BY aggregates rows that share values into summary rows (used with COUNT, SUM, AVG). ORDER BY sorts the result set ascending (default) or descending. They serve different purposes and can be used together.
Functions that compute a single value over a set of rows: COUNT, SUM, AVG, MIN, MAX. They are commonly used with GROUP BY to summarise data per group.
A subquery is a query nested inside another. A non-correlated subquery runs once and its result is used by the outer query. A correlated subquery references the outer query and runs once per outer row, so it is usually slower.
Organising tables to reduce redundancy and improve integrity. 1NF: atomic values; 2NF: no partial dependency on part of a composite key; 3NF: no transitive dependency on non-key columns. Denormalization trades redundancy for read speed.
A common approach: SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees); or use DENSE_RANK() OVER (ORDER BY salary DESC) and filter rank = 2. Mention handling of duplicates.
UNION combines result sets and removes duplicates (extra sort cost). UNION ALL combines them keeping duplicates and is faster. Both require the same number and compatible types of columns.
SELECT, FROM, WHERE, DISTINCT, ORDER BY, LIMIT. Practise filtering with AND/OR, IN, BETWEEN, LIKE and IS NULL.
COUNT, SUM, AVG, MIN, MAX with GROUP BY and HAVING. Learn to summarise data per category.
INNER, LEFT, RIGHT and FULL joins across multiple tables. Understand keys and how rows match.
Subqueries in WHERE/FROM/SELECT, EXISTS/IN, and UNION/INTERSECT/EXCEPT.
ROW_NUMBER, RANK, DENSE_RANK, and running totals; plus indexing and normalization basics.
Solve query challenges on a sample schema (employees, orders, products). Write the "second highest", "top N per group" and "running total" queries from memory.
Browse fresh internships and first jobs in SQL and related fields.
Browse Internships