Data & Analytics

SQL Interview Questions for Freshers: 18 Answers With Oracle Examples

18 SQL interview questions freshers face in Pakistan, with short model answers and Oracle examples on keys, NULLs, joins, grouping and ranking. You also get a five-step method for live query questions and a two-week practice plan you can follow in your browser.

SQL interview questions for freshers featured image with an Oracle query window

Quick answer

Most SQL interview questions for freshers climb through five levels: definitions, filtering and NULLs, joins, grouping and ranking. Learn a short answer for each, know Oracle traps such as = NULL, ROWNUM and column aliases, and answer live queries by restating, checking edge cases, writing simply, testing and explaining.

Key takeaways

  • • Use IS NULL, never = NULL; any comparison with NULL returns UNKNOWN.
  • • TRUNCATE can't be rolled back in Oracle, while DELETE can be before COMMIT.
  • • COUNT(*) counts every row; COUNT(column) skips NULLs.
  • • For top-N results, use ORDER BY with FETCH FIRST rather than ROWNUM.
  • • Ask about ties before writing a second-highest salary query.
  • • Practice free in Oracle FreeSQL for two weeks and type every query yourself.
Table of contents 29 sections
  1. How Do SQL Interview Questions for Freshers Work?
  2. Basic SQL Interview Questions on Keys and Commands
  3. 1. What is the difference between a database, a DBMS and SQL?
  4. 2. How is a primary key different from a unique key?
  5. 3. What are DDL, DML, DCL and TCL?
  6. 4. What's the difference between DELETE, TRUNCATE and DROP?
  7. 5. What's the difference between WHERE and HAVING?
  8. NULL Questions That Trip Up Freshers
  9. 6. Why does WHERE commission = NULL return no rows?
  10. 7. How does Oracle treat an empty string?
  11. 8. What's the difference between COUNT(*) and COUNT(column)?
  12. Which Join Questions Should You Expect?
  13. 9. What's the difference between an INNER JOIN and a LEFT JOIN?
  14. 10. How do you find customers who have never placed an order?
  15. 11. What is a self join?
  16. Grouping and Ranking Queries Interviewers Love
  17. 12. How do you find duplicate CNIC numbers in a table?
  18. 13. How do you find the second-highest salary?
  19. 14. What's the difference between RANK, DENSE_RANK and ROW_NUMBER?
  20. 15. How do you return the top three products by sales?
  21. Oracle SQL Interview Questions on ROWNUM, Sets and Aliases
  22. 16. Why does WHERE ROWNUM > 1 return no rows?
  23. 17. What's the difference between UNION and UNION ALL?
  24. 18. Why can't you use a column alias in the WHERE clause?
  25. How Should You Answer a Live Query Question?
  26. A Two-Week SQL Practice Plan
  27. Where SQL Skills Lead in Pakistan
  28. Learn SQL With PSTA
  29. Tonight: Write Three Queries From Memory

Picture an example many freshers will recognize: you're halfway through a round of SQL interview questions at a software house in Islamabad, and the interviewer asks for the second-highest salary in an employees table. You know SELECT, WHERE and ORDER BY well, yet the blank editor makes your mind go quiet. Nothing about the question was hard. You just hadn't practiced saying and writing the answer under a little pressure.

Most SQL interview questions for freshers aren't trick questions. They check whether you can turn a plain business request into a correct query, and whether you understand why it works. This guide collects 18 questions that come up again and again, with short model answers and Oracle examples you can run free in your browser.

Here's what you'll take away:

  • The five levels most fresher SQL rounds move through, from definitions to ranking queries
  • Clear, interview-length answers to 18 common questions, grouped by topic
  • The Oracle-specific traps (ROWNUM, empty strings, aliases) that catch prepared candidates
  • A five-step method for answering a live query question calmly
  • A two-week practice plan that needs nothing more than a browser

How Do SQL Interview Questions for Freshers Work?

A fresher round is often a short conversation with one developer or team lead, sometimes after a written test. The questions tend to climb in five levels, and the interviewer stops climbing when your answers get shaky.

  1. Definitions and commands. Keys, constraints, and the difference between DDL and DML.
  2. Filtering and NULLs. WHERE conditions, and how missing values behave.
  3. Joins. Combining two or three tables without losing or duplicating rows.
  4. Grouping. GROUP BY, HAVING and counting duplicates.
  5. Ranking. Top-N results and analytic functions such as DENSE_RANK.

Levels 1 and 2 decide whether you pass. Levels 4 and 5 decide how strongly the panel remembers you. So don't skip the basics to rush into window functions; a shaky answer about NULL costs more than a missing answer about analytic functions.

Five levels of SQL interview questions for freshers, from definitions to ranking
Fresher SQL rounds usually climb from definitions to ranking queries.

All examples below use Oracle syntax, since that's what our course teaches, but nearly every idea carries over to MySQL, PostgreSQL and SQL Server.

Basic SQL Interview Questions on Keys and Commands

These first five SQL interview questions check your vocabulary. Keep each answer under a minute and add one small example.

1. What is the difference between a database, a DBMS and SQL?

A database is the organized data itself. A database management system, such as Oracle Database or MySQL, is the software that stores that data, controls access and keeps it consistent. SQL is the language you use to ask the DBMS for data or change it. A short way to say it: the database is the warehouse, the DBMS is the warehouse staff, and SQL is the order form.

2. How is a primary key different from a unique key?

Both stop duplicate values. A primary key also forbids NULL, and a table can have only one. You can add several unique constraints, for example on email and on CNIC number in a students table, while student_id stays the primary key. Mention that a foreign key in another table usually points to the primary key, and you've shown you understand why it matters.

3. What are DDL, DML, DCL and TCL?

  • DDL (Data Definition Language) changes structure: CREATE, ALTER, DROP, TRUNCATE.
  • DML (Data Manipulation Language) changes rows: INSERT, UPDATE, DELETE, MERGE.
  • DCL (Data Control Language) handles permissions: GRANT, REVOKE.
  • TCL (Transaction Control Language) manages transactions: COMMIT, ROLLBACK, SAVEPOINT.

4. What's the difference between DELETE, TRUNCATE and DROP?

Expect this one in some form. Oracle's documentation says you can't roll back a TRUNCATE TABLE statement, and you can't use FLASHBACK TABLE to get the rows back either (Oracle TRUNCATE TABLE reference). The same page notes that TRUNCATE can be faster than DELETE, especially on tables with many triggers and indexes.

Command Removes WHERE Allowed? Undo With ROLLBACK? Table Survives?
DELETE Chosen rows or all rows Yes Yes, before COMMIT Yes
TRUNCATE All rows No No Yes
DROP Rows and the table itself No No No

5. What's the difference between WHERE and HAVING?

WHERE filters individual rows before they are grouped. HAVING filters whole groups after aggregate functions such as SUM or COUNT have run. Oracle's reference on aggregate functions describes HAVING as the place to remove groups based on aggregate results rather than on single row values (Oracle aggregate functions).

SELECT city, COUNT(*) AS students
FROM   students
WHERE  status = 'ACTIVE'
GROUP  BY city
HAVING COUNT(*) > 20;

NULL Questions That Trip Up Freshers

NULL means "unknown" or "missing", not zero and not a blank. Interviewers like NULL questions because a candidate who memorized syntax often gets them wrong.

6. Why does WHERE commission = NULL return no rows?

Any comparison with NULL, using = or <>, gives UNKNOWN rather than TRUE or FALSE, and a WHERE clause treats UNKNOWN like FALSE. Oracle's documentation says to test for missing values only with IS NULL or IS NOT NULL (Oracle nulls reference). The fix is one word: WHERE commission IS NULL.

7. How does Oracle treat an empty string?

Oracle currently treats a zero-length character value as NULL. The same documentation page warns that this may change in a future release and advises you not to rely on it. Saying both halves of that answer shows you read beyond a tutorial.

8. What's the difference between COUNT(*) and COUNT(column)?

COUNT(*) counts every row. COUNT(phone) counts only rows where phone isn't NULL. Oracle states that all aggregate functions except COUNT(*), GROUPING and GROUPING_ID ignore NULLs, and that COUNT never returns NULL. So if 100 students exist and 12 have no phone number, COUNT(*) returns 100 and COUNT(phone) returns 88.

Which Join Questions Should You Expect?

Most real reports need SQL joins across at least two tables, so expect at least one join question even in a short round. Join-based SQL interview questions are also where interviewers watch how you think, so draw two tiny tables on paper if it helps.

9. What's the difference between an INNER JOIN and a LEFT JOIN?

An INNER JOIN keeps only rows that match in both tables. A LEFT JOIN keeps every row from the left table and fills the right side with NULL where no match exists. In a shop database, an inner join of customers and orders lists only customers who have bought something. A left join lists all customers, buyers or not.

10. How do you find customers who have never placed an order?

There are three good answers, and naming more than one earns credit:

-- Option A: LEFT JOIN and check for NULL
SELECT c.customer_id, c.name
FROM   customers c
LEFT   JOIN orders o ON o.customer_id = c.customer_id
WHERE  o.order_id IS NULL;

-- Option B: NOT EXISTS
SELECT c.customer_id, c.name
FROM   customers c
WHERE  NOT EXISTS (SELECT 1 FROM orders o
                   WHERE o.customer_id = c.customer_id);

Option C uses Oracle's MINUS operator, which returns distinct rows from the first query that the second query doesn't return.

11. What is a self join?

A self join joins a table to itself using two aliases. The classic case is an employees table where manager_id points to another employee's employee_id. To print each employee next to their manager's name, join employees e to employees m on e.manager_id = m.employee_id. Use a LEFT JOIN if you want the head of the company, who has no manager, to stay in the list.

Grouping and Ranking Queries Interviewers Love

The next four SQL interview questions ask you to write a query, not define a term. Type each one out at least twice before your interview.

12. How do you find duplicate CNIC numbers in a table?

SELECT cnic, COUNT(*) AS times_used
FROM   applicants
GROUP  BY cnic
HAVING COUNT(*) > 1;

It's a realistic question for anyone working with admission forms, bank records or payroll data, where the same person can be entered twice.

13. How do you find the second-highest salary?

Back to the example from the start. A clean Oracle answer uses DENSE_RANK:

SELECT DISTINCT salary
FROM  (SELECT salary,
              DENSE_RANK() OVER (ORDER BY salary DESC) AS rnk
       FROM   employees)
WHERE  rnk = 2;

Before writing it, ask one question: "If two people share the top salary, should the second-highest be the next different amount?" That single question tells the interviewer you think about ties, which is what this question really tests.

14. What's the difference between RANK, DENSE_RANK and ROW_NUMBER?

All three number rows in a chosen order. ROW_NUMBER gives every row a unique number, even when values tie. RANK gives tied rows the same rank and then skips numbers. DENSE_RANK also gives ties the same rank but doesn't skip. Oracle's DENSE_RANK page shows two employees tied at rank 2, with the next employee ranked 3 rather than 4 (Oracle DENSE_RANK reference). Under RANK, that next employee would be 4.

15. How do you return the top three products by sales?

SELECT product_name, total_sales
FROM   product_sales
ORDER  BY total_sales DESC
FETCH  FIRST 3 ROWS ONLY;

The row limiting clause supports FETCH FIRST, an OFFSET to skip rows, and WITH TIES to include rows that tie with the last one returned. Always pair it with ORDER BY. Without a sort order, "top three" has no fixed meaning.

Oracle SQL Interview Questions on ROWNUM, Sets and Aliases

If the job ad mentions Oracle, PL/SQL or a bank's core system, expect at least one of these Oracle SQL interview questions.

16. Why does WHERE ROWNUM > 1 return no rows?

Oracle assigns ROWNUM 1 to the first row fetched. That row fails the condition, so the next row becomes the first and also gets ROWNUM 1. Every row fails the same way. Oracle's ROWNUM page also explains that if ORDER BY sits in the same query as a ROWNUM condition, the rows are numbered before sorting, so "top 10" can return the wrong 10 (Oracle ROWNUM reference). The same page recommends the row limiting clause for this job.

17. What's the difference between UNION and UNION ALL?

UNION returns only distinct rows from both queries. UNION ALL returns every row, duplicates included. Because UNION ALL skips the duplicate check, it's usually the cheaper choice when you know the two sets can't overlap, such as this year's and last year's invoices.

18. Why can't you use a column alias in the WHERE clause?

Oracle's SELECT reference says a column alias can be used in the ORDER BY clause but not in other clauses of the same query. So WHERE annual_pay > 1200000 fails if annual_pay is an alias. Repeat the expression in WHERE, or wrap the query in a subquery and filter outside it.

Before and after Oracle query fixes for NULL, ROWNUM and column alias mistakes
Three common Oracle mistakes and the corrected versions.

How Should You Answer a Live Query Question?

Knowing the answers to SQL interview questions is half the work. The other half is staying organized when someone is watching you type. Use the same five steps every time:

  1. Restate the request. "So you want each city with more than 20 active students?" This catches misunderstandings early.
  2. Ask about edge cases. NULLs, ties and empty tables are the usual three.
  3. Write the simplest correct query first. Clever can come later.
  4. Test it on three rows in your head or on paper. Include one row with a NULL.
  5. Explain one alternative. For example, NOT EXISTS instead of a LEFT JOIN, and when you'd pick it.
Five steps to answer a live SQL query question in an interview
A repeatable five-step method for live query questions.

If you don't know an answer, say what you'd check. "I'm not sure whether this database treats an empty string as NULL, so I'd test it with a quick SELECT" is a far better answer than a confident guess.

A Two-Week SQL Practice Plan

You don't need to install anything to start. Oracle FreeSQL runs real Oracle SQL in your browser, is free with no time limit, and lets you begin without an account; a free account adds saved work and your own schema (Oracle FreeSQL). Spend 45 to 60 minutes a day, type every query yourself, and you'll have touched every topic in the SQL interview questions above.

Days Focus Practice Task
1–2 SELECT, WHERE, ORDER BY Filter a students table by city and fee status
3–4 NULLs and single-row functions Count missing phone numbers with COUNT(*) and COUNT(phone)
5–7 Joins Customers with and without orders; employees with managers
8–9 GROUP BY and HAVING Find duplicate CNIC numbers and city totals
10–11 Subqueries and set operators Rewrite one query with NOT EXISTS and with MINUS
12–13 Ranking and top-N Second-highest salary, top three products WITH TIES
14 Mock interview Ask a friend to read out five questions and time your answers

On day 14, answer out loud. If spoken English is the harder part for you, read our English interview questions and answers post, which handles the spoken side of the same round.

Where SQL Skills Lead in Pakistan

SQL is one of the most widely used skills in software work. In the Stack Overflow 2025 Developer Survey, 58.6% of all respondents and 61.3% of professional developers said they had used SQL in the past year. PostgreSQL (55.6%) and MySQL (40.5%) were far more common among respondents than Oracle Database (10.6%). That's a good reason to learn standard SQL first and treat Oracle-specific features as a layer on top.

At home, the demand side keeps growing. State Bank of Pakistan figures, as covered by ProPakistani, put the country's IT and IT-enabled services exports at $4.6 billion for FY2025-26, an all-time high and 20% more than a year earlier. Much of that work runs on databases.

Fresher roles where SQL interview questions commonly appear include junior data analyst, backend developer, QA engineer, MIS or reporting officer, and trainee database administrator. If you're preparing for a data analyst interview, pair SQL with a reporting tool; our comparison of Power BI vs Excel explains where to start. If you want backend or automation work, Python is the natural partner, and our list of Python projects for beginners includes ideas that read from a database.

Learn SQL With PSTA

If you want to learn SQL in Pakistan with guided practice and feedback, the Oracle Database 19c Masterclass: SQL, PL/SQL & Administration is a 12-week, beginner-level course you can take online from anywhere in Pakistan or on campus in Abbottabad. Its current fee on the course page is Rs. 33,000, down from Rs. 45,000.

  • Module 1 covers the SQL in this article: SELECT, restricting and sorting, single-row functions, aggregation and grouping, joins and set operators, subqueries and DDL.
  • Module 2 moves into PL/SQL: control structures, cursors, exception handling, procedures, functions, packages and triggers.
  • Later modules cover architecture, security, RMAN backup and recovery, performance tuning and multitenant databases, ending with a capstone project.

If you're heading toward analyst or automation work, the natural next steps are the Power BI course or the Advanced Python course. Browse every program on the courses page, apply through online admission, or send your questions to +92 314 5424399 on WhatsApp. Prefer to talk in person? Visit us in Abbottabad at Mandian, Old College Road, across from FIMS College.

Tonight: Write Three Queries From Memory

Open Oracle FreeSQL and, without looking at this page, write three queries: customers with no orders, duplicate CNIC numbers, and the second-highest salary. Then compare them with the answers above. Whatever you got wrong is your study list for tomorrow, and that list is worth more than reading another set of SQL interview questions.

Frequently asked questions

Is SQL enough to get a job as a fresher in Pakistan?

SQL alone can open doors to junior reporting, MIS and trainee database roles, but many employers want it paired with something else. Analysts usually add Excel or Power BI, while developers add a language such as Python, Java or JavaScript. Treat SQL as the base skill that makes your second skill far more useful, and show both in two or three small portfolio projects.

Should I learn Oracle SQL or MySQL first for interviews?

Learn standard SQL first, because SELECT, joins, GROUP BY and subqueries work almost the same everywhere. Then learn the details of the database named in the job ad. If you're targeting banks or large enterprise systems that mention Oracle or PL/SQL, practice Oracle features such as ROWNUM, FETCH FIRST and MINUS. Moving to another database later mostly means learning small differences.

How much preparation time does a fresher SQL interview need?

If you already know basic SELECT queries, two focused weeks of daily practice is usually enough for a fresher round. Starting from zero, give yourself six to eight weeks so joins and grouping become comfortable. The key is typing queries yourself and explaining them aloud, not reading more lists of questions.

Do fresher SQL interviews ask about PL/SQL?

Only when the role mentions Oracle development or database work. In that case, expect basic questions such as the difference between a procedure and a function, what a trigger does, and how exception handling works. For analyst and general developer roles, interviewers usually stay with plain SQL, so prepare that first.

Can I practice Oracle SQL without installing anything?

Yes. Oracle FreeSQL runs real Oracle SQL in your web browser for free, with no time limit, and you can start without creating an account. A free account adds saved work and your own schema. It's enough for every query in this guide and for a full two-week practice plan.

What should I do if I can't solve a query during the interview?

Don't go silent. Explain how you'd break the problem down, write the part you're sure about, and say what you would test next. Interviewers often care more about your reasoning than a perfect final query. A calm partial answer with clear thinking usually leaves a better impression than a rushed guess.

Are SQL interview questions different for data analysts and developers?

The basics overlap, but the focus shifts. Analyst interviews lean toward grouping, filtering, ranking and turning a business question into a report. Developer interviews add keys, constraints, indexes, transactions and how the application writes data. Read the job description closely and practice the questions that match the role you're applying for.

Sources & references

  1. Stack Overflow 2025 Developer Survey: Technology survey.stackoverflow.co
  2. Oracle Database 19c SQL Reference: TRUNCATE TABLE docs.oracle.com
  3. Oracle Database 19c SQL Reference: Nulls docs.oracle.com
  4. Oracle Database 19c SQL Reference: Aggregate Functions docs.oracle.com
  5. Oracle Database 19c SQL Reference: ROWNUM Pseudocolumn docs.oracle.com
  6. Oracle Database 19c SQL Reference: DENSE_RANK docs.oracle.com
  7. Oracle FreeSQL oracle.com
  8. ProPakistani: Pakistan's IT Exports Reach All-Time High of $4.6 Billion propakistani.pk

Last reviewed & updated on by Umar Qureshi. Written by the PSTA team in Abbottabad, Pakistan.

Share this article
Umar Qureshi
About the author

Umar Qureshi

Trainer at Professional Skills & Tech Academy

Umar Qureshi is an IT skills trainer and instructor at Professional Skills & Tech Academy (PSTA) in Abbottabad. He teaches programming, digital marketing and practical computer skills, with a focus on hands-on projects that students can use in jobs and freelancing. His articles turn technical topics into clear, step-by-step guidance for students and job seekers across Pakistan.

Oracle Database 19c Masterclass: SQL, PL/SQL & Administration course at PSTA
Recommended course

Oracle Database 19c Masterclass: SQL, PL/SQL & Administration

Turn this guide into a career: hands-on training with real projects, online across Pakistan or on-campus in Abbottabad · 12 Weeks.

Rs. 33,000.00 Rs. 45,000.00

Comments

No comments yet — ask a question or share your experience.

Leave a comment

Comments are moderated. Please be respectful — no links to spam.