Quick Answer: SQL Interview Questions 2026
The top 40 SQL interview questions asked at TCS, Wipro, Infosys, Cognizant, Accenture, Capgemini, and HCL in 2026 cover six clusters: basic SQL (SELECT, WHERE, ORDER BY), joins (INNER, LEFT, RIGHT, FULL OUTER, SELF), aggregates and GROUP BY (COUNT, SUM, AVG, HAVING), subqueries (single-row, multi-row, correlated, EXISTS), DDL/DML (CREATE, INSERT, UPDATE, DELETE, constraints), and real scenarios (second highest salary, duplicates, employees without managers, running totals). Most fresher interviews include 8-12 SQL MCQs (TCS NQT, Wipro NLTH) plus 2-3 written queries (Infosys InfyTQ, Cognizant GenC). Experienced interviews (3+ years) add window functions (ROW_NUMBER, RANK, LAG, LEAD, SUM OVER), CTEs, and query optimization (EXPLAIN, indexes). For the full Q&A collection with 25 curated questions, see the TutorsBot SQL Interview Questions hub.
The 6 Topic Clusters Asked Most Often
Cluster 1: Basic SQL (SELECT, WHERE, ORDER BY, DISTINCT)
Round 1 in nearly every interview. The expected baseline questions: What is the difference between DISTINCT and GROUP BY? How do you sort results (ORDER BY ASC/DESC, multiple columns)? How do you limit the number of rows returned (LIMIT n in MySQL/PostgreSQL/SQLite, TOP n in SQL Server, FETCH FIRST n ROWS ONLY in standard SQL)? How do you filter rows (WHERE with comparison operators, IN, BETWEEN, LIKE, IS NULL, AND/OR/NOT)? What is the difference between WHERE and HAVING? How do you alias columns and tables (SELECT col AS alias, FROM table alias)? TCS NQT and Wipro NLTH include 3-5 questions on this cluster; they are easy wins if you prepare.
Cluster 2: Joins (INNER, LEFT, RIGHT, FULL OUTER, SELF, CROSS)
Where most SQL interview time goes. The non-negotiable question: explain the difference between INNER, LEFT, RIGHT, and FULL OUTER JOIN with examples. Other classics: What is a self join (a table joined to itself, useful for employees-managers, employees-in-the-same-department)? What is a CROSS JOIN (Cartesian product, every row of A paired with every row of B)? What is the difference between JOIN and APPLY (SQL Server)? What is a natural join (joins on columns with the same name, rarely used in practice)? Most fresher interviews ask you to write 2-3 join queries against an employees/departments schema; Cognizant GenC Next adds harder multi-table joins (3+ tables with aggregations).
Cluster 3: Aggregates and GROUP BY
Tested heavily at Capgemini and Accenture. Questions: What aggregate functions are available (COUNT, SUM, AVG, MIN, MAX, plus database-specific ones like STRING_AGG, ARRAY_AGG, GROUP_CONCAT)? What is the difference between WHERE and HAVING (WHERE filters rows before grouping; HAVING filters groups after aggregation)? Can you use column aliases in GROUP BY (no in most databases - use the underlying expression)? What does COUNT(*) vs COUNT(column) return (COUNT(*) counts all rows including NULLs; COUNT(column) counts only non-NULL values)? What is the difference between GROUP BY and DISTINCT (they often produce the same result for a single column, but GROUP BY is required when you also want aggregates)?
Cluster 4: Subqueries
The classic differentiator between fresher and mid-level answers. Single-row subqueries return one value (used with =, <, >, etc.). Multi-row subqueries return multiple rows (used with IN, ANY, ALL). Correlated subqueries reference the outer query and run once per row (slower than non-correlated). EXISTS tests for the existence of rows in the subquery (returns TRUE/FALSE). Common interview questions: write a query to find employees whose salary is greater than the average salary in their department (correlated subquery or window function). What is the difference between a correlated and non-correlated subquery (execution frequency: correlated runs per outer row, non-correlated runs once)? When would you use a subquery vs a JOIN (modern SQL prefers JOIN for most cases; subqueries are still needed for EXISTS, NOT EXISTS, and complex aggregations)?
Cluster 5: DDL/DML and Constraints
Asked at TCS Digital and Infosys Power Programmer. Questions on CREATE TABLE (column definitions, data types, constraints), ALTER TABLE (ADD/DROP/MODIFY column, ADD/DROP constraint), constraints (PRIMARY KEY, FOREIGN KEY with referential actions ON DELETE CASCADE/SET NULL/RESTRICT, UNIQUE, CHECK, NOT NULL, DEFAULT), data types (INT, BIGINT, DECIMAL, FLOAT, VARCHAR, CHAR, TEXT, DATE, TIMESTAMP, BOOLEAN, JSON, BLOB), indexes (CREATE INDEX, when to use, B-tree vs hash, covering index), and views (CREATE VIEW, updatable views, materialized views). Common fresher question: explain the difference between CHAR and VARCHAR (CHAR is fixed-length, padded with spaces, slightly faster for known-length data; VARCHAR is variable-length, saves space).
Cluster 6: Real Scenarios (Second Highest Salary, Duplicates, Running Totals)
The most-tested questions across all companies. Five classics that come up in 80%+ of fresher SQL interviews: (1) Find the second highest salary - several approaches (LIMIT/OFFSET, subquery, window function with DENSE_RANK). (2) Find duplicate rows in a table - GROUP BY column HAVING COUNT(*) > 1, or window function ROW_NUMBER() OVER (PARTITION BY col). (3) Find employees who don't have a manager - LEFT JOIN employees e2 ON e.manager_id = e2.id WHERE e2.id IS NULL. (4) Delete duplicate rows keeping one - use ROW_NUMBER in a subquery to identify duplicates, then DELETE the rest. (5) Calculate running total - SUM(col) OVER (ORDER BY date). For experienced interviews, expect follow-ups like "what about ties in second highest salary" (use DENSE_RANK instead of LIMIT) or "what about when salary has NULLs" (filter NULLs in the WHERE clause).
Top 10 SQL Coding Questions Asked in 2026
The live coding questions that came up most often in 2026 fresher SQL interviews at TCS/Wipro/Infosys/Cognizant/Accenture/Capgemini/HCL:
- Find the second highest salary from the employees table
- Find all employees who have the same salary as another employee
- Find the top 3 highest-paid employees in each department
- Calculate the running total of sales by month
- Find employees who joined in the last 6 months
- Delete duplicate rows from a table keeping the row with the lowest id
- Find the department with the highest average salary
- Find employees whose manager is in a different department
- Find customers who placed orders in 3 consecutive months
- Find the gap in dates between consecutive orders for each customer
For the full 40-question list with expected SQL syntax, edge cases, and the company that asks each one, see the TutorsBot SQL Interview Questions hub.
Common Fresher Pitfalls to Avoid
- Confusing WHERE and HAVING: WHERE filters rows, HAVING filters groups; aggregate functions are only allowed in HAVING (or in SELECT with GROUP BY)
- Forgetting to alias aggregates: SELECT COUNT(*) gives a column named COUNT(*); use AS alias for readability
- Confusing INNER and LEFT JOIN: INNER excludes unmatched rows; LEFT keeps all rows from the left table
- NULL comparisons: = NULL never matches; use IS NULL or IS NOT NULL; COUNT(column) excludes NULLs, COUNT(*) includes them
- Missing the GROUP BY column: Every non-aggregated column in SELECT must appear in GROUP BY
- Confusing UNION and JOIN: UNION combines rows vertically (same columns); JOIN combines columns horizontally (different columns from different tables)
- Not handling ties: LIMIT/OFFSET skips ties; use DENSE_RANK or RANK when ties matter
- Subquery vs JOIN performance: Modern query optimizers treat subqueries and JOINs similarly; don't assume subquery is slower without EXPLAIN evidence
How to Prepare in 30 Days
The strongest 30-day fresher SQL interview preparation plan:
- Week 1 - Foundations: Complete SQLBolt (free, 18 lessons), W3Schools SQL tutorial, write 20+ queries against a sample employees database (try SQL Murder Mystery or the Northwind sample database)
- Week 2 - Joins and aggregates: Practice 30+ join queries, write the second highest salary in 4 different ways (LIMIT, subquery, window function, CTE), practice GROUP BY with HAVING and multiple aggregates
- Week 3 - Subqueries and DDL: Practice correlated vs non-correlated subqueries, learn the difference between UNION and UNION ALL, write CREATE TABLE statements with all constraint types
- Week 4 - Window functions and mock tests: Learn ROW_NUMBER, RANK, DENSE_RANK, LAG, LEAD, SUM OVER; take 2-3 timed mock tests on HackerRank SQL; review the SQL Interview Questions hub for the full Q&A collection
For a structured, project-based path from SQL basics to interview-ready, the TutorsBot Full Stack Development training covers database design, schema management, and API development end-to-end.
Frequently Asked Questions
How many SQL questions are asked in TCS NQT 2026?
TCS NQT 2026 typically includes 8-12 SQL questions in the coding/technical section for Digital and Prime profiles, plus 1-2 advanced SQL problems. For Ninja profiles, the count is lower (5-8 MCQs, 1 written query). TCS Digital adds harder scenarios including window functions and CTEs.
Is SQL enough to get placed in TCS/Wipro/Infosys?
SQL alone is rarely enough - companies test a combination of SQL, Python or Java, DSA, and aptitude/reasoning. The strongest fresher profile combines: SQL (intermediate to advanced, including window functions), one strong programming language (Python or Java), DSA (50-100 problems on LeetCode Easy/Medium), communication skills, and 2-3 small projects on GitHub. Cognizant GenC and Capgemini have the heaviest SQL testing of the major service companies.
What is the salary for SQL freshers at these companies in 2026?
Salary bands for freshers with SQL skills in 2026: TCS Ninja ₹3.36 LPA, TCS Digital ₹7-8 LPA, TCS Prime ₹9-11 LPA. Wipro ₹3.5-5 LPA. Infosys (InfyTQ Power Programmer) ₹6.5-9.5 LPA, regular InfyTQ ₹3.6 LPA. Cognizant GenC ₹4.5-6 LPA, GenC Next ₹7-12 LPA. Accenture AASE ₹4.5-6 LPA, AASS ₹6-9 LPA. Capgemini ₹4-6 LPA. HCL ₹3.5-5.5 LPA. Product companies (Flipkart, PhonePe, Razorpay) pay 2-3x these bands for SQL-heavy data analyst and analytics engineer roles.
What is the best resource for SQL interview preparation?
The strongest resources are: SQLBolt (free interactive lessons), W3Schools SQL tutorial (free reference), Mode Analytics SQL Tutorial (free advanced topics), HackerRank SQL domain (free hands-on practice), LeetCode Database problems (free Easy/Medium), the Northwind or Sakila sample databases for practice queries, and the TutorsBot SQL Interview Questions hub for curated 25 questions at all difficulty levels. For experienced interview prep, focus on window functions (the official PostgreSQL or SQL Server window function tutorial), query optimization (use EXPLAIN plans), and CTEs (Common Table Expressions).
Is SQL enough for data analyst interviews at product companies?
For entry-level data analyst roles at product companies (Flipkart, PhonePe, Razorpay, Cred), SQL is the core requirement - expect 3-4 SQL rounds covering joins, window functions, aggregations, and at least one complex business question. Strong SQL plus Python (pandas) and a data visualization tool (Tableau, Power BI, Looker) is the strongest entry-level profile. For senior data analyst or analytics engineer roles, expect SQL plus Python/R for statistical analysis, A/B testing knowledge, and a take-home assignment.
Resources and Next Steps
The authoritative sources listed (W3Schools, SQLBolt, Mode Analytics, PostgreSQL documentation, HackerRank) are the canonical references for SQL fundamentals and interview preparation. For the full 25-question curated Q&A collection at all difficulty levels, see the TutorsBot SQL Interview Questions hub. For related interview prep, see our Python interview questions, DBMS interview questions, and Normalization in DBMS guides.



