Entry-Level SQL & Python Interview Handbook
SQL Basics
Database: Organized collection of data.
DBMS: Software to manage databases.
RDBMS: DBMS using related tables (e.g., MySQL, PostgreSQL).
Primary Key: Uniquely identifies each row.
Foreign Key: Links two tables.
NULL: Missing/unknown value.
SQL Queries
SELECT retrieves data. WHERE filters rows. ORDER BY sorts results. DISTINCT removes
duplicates. LIMIT restricts number of rows.
Example: SELECT name FROM employees WHERE salary>50000 ORDER BY salary
DESC LIMIT 5;
Filtering
Operators: AND, OR, NOT, IN, BETWEEN, LIKE, IS NULL.
Aggregate Functions
COUNT counts rows, SUM totals values, AVG computes average, MAX largest, MIN
smallest.
GROUP BY & HAVING
GROUP BY groups rows. HAVING filters groups after aggregation.
Joins
INNER JOIN: matching rows.
LEFT JOIN: all left rows + matches.
RIGHT JOIN: all right rows + matches.
FULL OUTER JOIN: all rows from both (if supported).
CRUD
CREATE, INSERT, SELECT, UPDATE, DELETE.
Transactions
COMMIT saves changes. ROLLBACK undoes changes. SAVEPOINT creates rollback
points.
Normalization
1NF: atomic values. 2NF: remove partial dependency. 3NF: remove transitive
dependency.
Python Basics
Variables store data. Common types: int, float, str, bool, list, tuple, set, dict.
Operators
Arithmetic (+,-,*,/), Comparison (==,!=,<,>), Logical (and, or, not).
Control Flow
if/elif/else choose paths. for and while repeat tasks. break exits loop, continue skips
iteration.
Functions
Define using def. Use parameters and return values.
Data Structures
List: mutable ordered. Tuple: immutable ordered. Set: unique items. Dictionary:
key-value pairs.
Strings
Useful methods: split, join, replace, find, strip, upper, lower.
Exceptions
Use try/except/finally to handle errors gracefully.
Files
open(), read(), write(), append(), close() or use with statement.
OOP
Class is blueprint. Object is instance. __init__ is constructor. Inheritance reuses code.
Useful Libraries
math, random, datetime, os, sqlite3.
Python + SQL
Use sqlite3 to connect to databases, execute queries, fetch results, commit changes.
Interview Q&A;
WHERE vs HAVING: WHERE filters rows before grouping; HAVING filters grouped data.
DELETE vs TRUNCATE vs DROP: DELETE removes rows, TRUNCATE removes all rows
quickly, DROP removes the table.
List vs Tuple: List is mutable; Tuple is immutable.
== vs is: == compares values; is compares object identity.
Mutable vs Immutable: Lists are mutable; strings and tuples are immutable.