Interview Q&A / SQL & DBMS
SQL & DBMS interview questions
Joins, keys, normalisation, indexes and transactions for placement and backend interviews.
Prefer rapid revision? Practise SQL & DBMS short interview answers →
- Why can't you use a column alias in the WHERE clause?
WHERE runs before SELECT, so the alias does not exist yet when the filter is evaluated. Repeat the expression, or put the query in a subquery or CTE and filter outside.
BeginnerQuick answer1 min read - Why does SELECT with GROUP BY fail when you pick a column that is not grouped?
After grouping, each group becomes one output row, so a column that is neither in GROUP BY nor inside an aggregate has many possible values and the database cannot pick one. Group by it or aggregate it.
BeginnerQuick answer1 min read - Write a query to list departments that have more than 5 employees.
Group by department and filter groups with HAVING COUNT(*) > 5. WHERE cannot be used because the count exists only after grouping.
BeginnerQuick answerCoding1 min read