Skip to content
SQL interview questions for freshers: joins, GROUP BY, duplicates and window functions

Quick answer: The most common SQL interview questions for freshers cover WHERE vs HAVING, joins, GROUP BY, duplicates, the second highest value, NULL handling and window functions such as ROW_NUMBER and RANK. Practise each on real tables and explain your query out loud. Our Data Analytics with AI course teaches SQL from joins to window functions.

10core questions covered
4 monthsData Analytics course
2 monthsinternship included
Anygraduate can apply

SQL is the skill data analyst interviews test first, because almost every analysis starts with pulling data out of a database. This guide lists ten questions that freshers are commonly asked, gives a short answer for each, and shows what the interviewer is really checking. Use it as a practice list, not something to memorise.

The 10 SQL questions freshers should practise

Learn the idea behind each question first, then write the query yourself on a small table of customers and orders. Interviewers care more about your reasoning than about perfect syntax.

Ten SQL interview questions for freshers: WHERE vs HAVING, joins, GROUP BY, duplicates, second highest value, NULLs, CTEs and window functions
The ten SQL questions freshers meet most often.
Common SQL interview questions and what each one tests
QuestionWhat the interviewer checks
WHERE vs HAVINGYou know filtering happens before and after grouping
INNER JOIN vs LEFT JOINYou can combine tables and keep unmatched rows when needed
GROUP BY with COUNT or SUMYou can summarise data per category
Find duplicate rowsYou can use GROUP BY with HAVING COUNT(*) > 1
Second highest valueYou know ranking, DENSE_RANK or LIMIT with OFFSET
NULL handlingYou use IS NULL and COALESCE, not = NULL
UNION vs UNION ALLYou know one removes duplicates and the other keeps them
Subquery vs CTEYou can write readable multi-step queries
ROW_NUMBER, RANK, DENSE_RANKYou understand window functions and ties
Primary key vs foreign keyYou understand how tables relate
  1. WHERE vs HAVINGWHERE filters rows before they are grouped. HAVING filters the groups after GROUP BY, for example HAVING COUNT(*) > 5.
  2. INNER JOIN vs LEFT JOININNER JOIN keeps only rows that match in both tables. LEFT JOIN keeps every row from the left table and fills the missing right side with NULL.
  3. Find duplicatesGroup by the columns that should be unique and keep groups with more than one row: GROUP BY email HAVING COUNT(*) > 1.
  4. Second highest valueRank the values with DENSE_RANK() OVER (ORDER BY amount DESC) and keep rank 2. DENSE_RANK handles ties correctly.
  5. NULL handlingNULL means unknown, so = NULL never matches. Use IS NULL, and COALESCE(col, 0) to replace NULL with a default.
  6. UNION vs UNION ALLUNION removes duplicate rows and is slower. UNION ALL keeps every row and is faster when duplicates do not matter.
  7. Subquery vs CTEA CTE, written with WITH, names a step so a long query reads top to bottom. The result is usually the same as a subquery.
  8. ROW_NUMBER, RANK, DENSE_RANKROW_NUMBER gives every row a unique number. RANK leaves gaps after ties. DENSE_RANK does not.
  9. Primary key vs foreign keyA primary key uniquely identifies a row in its own table. A foreign key points to the primary key of another table.
  10. GROUP BYEvery selected column must either be in GROUP BY or be inside an aggregate such as COUNT, SUM or AVG.

How to practise so the answers stick

  • Create three small tables (customers, orders, products) and write every query above against them.
  • Say each answer out loud in two sentences, because interviews are spoken.
  • Read the official PostgreSQL window functions tutorial and the CTE documentation for reliable explanations.
  • Check your result by hand on five rows before you trust a query.
A simple habit that impresses

Before you run a query, say what one row of the result should look like. If the output surprises you, you have found a bug in your thinking, not just your SQL.

Mistakes that cost freshers marks

  • Selecting columns that are not grouped. Every selected column must be grouped or inside an aggregate.
  • Using = NULL. It never matches; use IS NULL.
  • Forgetting that a LEFT JOIN can create NULLs. Filtering the right table in WHERE can silently turn it into an inner join.
  • Using SELECT * in an answer. Name the columns you need.

Scenario questions to expect

  • Return the top three customers by revenue for each month.
  • List customers who signed up but never placed an order.
  • Find the month with the largest drop in sales compared with the month before.

The first uses a window function, the second a LEFT JOIN with IS NULL, and the third LAG(). If you can explain these, you are ahead of most freshers.

How our course covers SQL

The Data Analytics with AI course at our J. P. Nagar centre runs for 4 months: 3 hours a day, Monday to Friday, plus a Saturday case clinic, with a weekend batch also available. You learn SQL joins, CTEs and window functions alongside advanced Excel, Power BI with DAX and Python with Pandas.

  • Projects: a retail sales dashboard, a credit-risk analysis, a marketing ROI and segmentation project, and a capstone presented to a panel.
  • Who can join: any graduate, including B.Com, BBA, BSc, BA Economics and engineering graduates, and working professionals.
  • Internship and fee: a 2-month internship is included, and the offer fee is ₹20,999 (regular ₹29,999).

Next, read the full data analyst roadmap.

Ready to try a class before you decide?Book a free demo class to see the syllabus, ask about fees and batches, and meet the team. Every course includes a 2-month internship, and classes run online and offline.Book on WhatsApp

Frequently asked questions

Which SQL topics matter most for a fresher data analyst interview?

Joins, GROUP BY with HAVING, finding duplicates, NULL handling, CTEs and window functions. These cover most fresher interview questions.

Do I need to memorise SQL syntax?

No. Interviewers care more about your logic. Know the core keywords and explain your approach clearly.

Which SQL database should I practise on?

Any standard one works. PostgreSQL and MySQL are free, and the concepts carry over between databases.

How long does it take to learn SQL for interviews?

It depends on your practice. In our Data Analytics with AI course, SQL is taught step by step over several weeks with daily practice.

Can a non-IT graduate learn SQL?

Yes. Our Data Analytics with AI course is open to any graduate, including B.Com, BBA and BSc graduates, and starts from the basics.

Not sure yet? Talk to us

Book a free demo class or ask for 1:1 guidance on WhatsApp at +91 99020 58603, or use the form on our contact page. You can also compare all our courses. Scholar’sEdge Academy is at Building No. 19, 25/1, 9th Cross Road, 2nd Phase, J. P. Nagar, Bengaluru, Karnataka 560078. Read how we write and check our articles in our editorial policy.