SQLMentor // interview: freshers

SQL Interview Questions for Freshers (0-2 Years Experience)

16 SQL questions pitched at the level you'll actually be asked as a fresher or early-career candidate — fundamentals, not trick questions. Every answer is explained in plain language first, with a short example you can run yourself in the free SQL editor.

Click each question to reveal the answer — try answering it out loud first. If a topic feels shaky, the Oracle SQL tutorial covers every one of these from scratch.


SQL & database basics

Q1. What is SQL, and what is a relational database?

Show answer

SQL (Structured Query Language) is the standard language for creating, querying, and modifying data in a relational database. A relational database stores data in tables made of rows and columns, with relationships between tables defined by shared key values — rather than one giant flat file.

Q2. What's the difference between SQL and something like MySQL or Oracle Database?

Show answer

SQL is the language. MySQL, Oracle Database, PostgreSQL, and SQL Server are database products — software that implements SQL, each with its own extensions and quirks on top of the shared standard. Learning SQL transfers between all of them; learning one product's specific syntax doesn't always transfer perfectly to another.

Q3. What are the main categories of SQL commands?

Show answer

Four categories: DDL (Data Definition Language) — CREATE, ALTER, DROP, which define schema objects; DML (Data Manipulation Language) — INSERT, UPDATE, DELETE, which change data; DQL (Data Query Language) — SELECT, which reads data; and DCL (Data Control Language) — GRANT, REVOKE, which manage permissions. Transaction control (COMMIT, ROLLBACK) is sometimes grouped as a fifth category, TCL.

Q4. What is a primary key? Can a table have more than one?

Show answer

A primary key is a column (or set of columns) that uniquely identifies every row in a table and can never be NULL. A table can have only one primary key — though that key can be composite, made up of more than one column together.

CREATE TABLE employees (
  employee_id INT PRIMARY KEY,
  last_name   VARCHAR(50)
);

Q5. What is a foreign key?

Show answer

A foreign key is a column in one table that references the primary key of another table, linking the two. It's how relational databases represent relationships — an employees table might have a department_id foreign key pointing at the departments table.


Querying basics

Q6. What is the difference between WHERE and HAVING?

Show answer

WHERE filters individual rows before any grouping happens. HAVING filters groups after GROUP BY has run, and is the only place you can filter using an aggregate function like COUNT or SUM.

SELECT department_id, COUNT(*) AS emp_count
FROM employees
GROUP BY department_id
HAVING COUNT(*) > 5;

Q7. What does DISTINCT do?

Show answer

DISTINCT removes duplicate rows from a query's result, based on every column selected. SELECT DISTINCT department_id FROM employees returns each department only once, no matter how many employees are in it.

Q8. What is the difference between CHAR and VARCHAR (or VARCHAR2 in Oracle)?

Show answer

CHAR(n) is fixed-length — it always stores exactly n characters, padding shorter values with spaces. VARCHAR/VARCHAR2(n) is variable-length — it stores only the characters actually used, up to a maximum of n. VARCHAR types are almost always the right default; CHAR is reserved for genuinely fixed-width data like a two-letter country code.

Q9. What is the difference between DELETE, TRUNCATE, and DROP?

Show answer

DELETE removes selected or all rows, one at a time, is DML, and can be rolled back — the table itself remains. TRUNCATE removes every row instantly, is DDL (and auto-commits in most databases), and generally cannot be rolled back — the table remains, empty. DROP removes the entire table — structure and data — permanently.

Q10. What is a JOIN, and what are the main types?

Show answer

A JOIN combines rows from two or more tables based on a related column. The main types: INNER JOIN returns only rows with a match in both tables; LEFT JOIN returns every row from the left table plus matches from the right (NULL where there's no match); RIGHT JOIN is the mirror image; FULL OUTER JOIN returns every row from both tables.

SELECT e.first_name, d.department_name
FROM employees e
JOIN departments d ON e.department_id = d.department_id;

Constraints & design

Q11. What is normalization?

Show answer

Normalization is organizing a database's tables to reduce duplicate data and avoid update anomalies — typically by splitting information into related tables connected by foreign keys, following a series of rules called normal forms. For example, storing a customer's address once in a customers table instead of repeating it on every one of their orders.

Q12. What is a NULL value, and how is it different from zero or an empty string?

Show answer

NULL means "unknown" or "no value at all" — it is not the same as 0 (a known numeric value) or '' (a known, empty piece of text). Because NULL is unknown, column = NULL never matches anything, even another NULL; you must use IS NULL or IS NOT NULL to test for it.

Q13. What is the difference between a UNIQUE constraint and a PRIMARY KEY?

Show answer

Both prevent duplicate values in a column. A table can have only one PRIMARY KEY, and it can never be NULL. A table can have several UNIQUE constraints, and unique columns are still allowed to contain NULLs (since NULL is never considered equal to another NULL).


Putting it together

Q14. What is the logical order in which a SQL query is processed?

Show answer

Even though you write SELECT first, the database evaluates a query in this order: FROMWHEREGROUP BYHAVINGSELECTORDER BY. Knowing this order explains why you can't filter on an aggregate in WHERE, and why a column alias defined in SELECT usually can't be used in WHERE.

Q15. What is an alias in SQL?

Show answer

An alias is a temporary name given to a column or table, using AS (often optional) — used to make output more readable or to shorten long table names in a query with multiple joins.

SELECT e.first_name AS name, e.salary AS pay
FROM employees AS e;

Q16. What is a subquery? Give a simple example.

Show answer

A subquery is a query nested inside another query, usually to compute a value the outer query then filters or compares against. It can appear in SELECT, FROM, or WHERE.

SELECT first_name, salary
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);