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 →
- How does GROUP BY work with more than one column?
GROUP BY with several columns makes one group for each unique combination of those column values, and aggregates are computed inside each combination.
BeginnerQuick answer1 min read - What is the difference between COUNT(*), COUNT(column) and COUNT(DISTINCT column)?
COUNT(*) counts all rows, COUNT(column) counts rows where that column is not NULL, and COUNT(DISTINCT column) counts the different non-NULL values.
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