SQL
5 SQL Practice Projects You Can Finish Before Your First Internship
Five small SQL projects, ordered from easy to tricky, with sample questions and queries you can build, test and explain in interviews.
Running SELECT * FROM students once won't get you through an internship interview. You'll be asked why you used a join, what one row in the result represents and how you checked that the answer was right. Five small databases you've queried yourself will prepare you much better than a giant "hospital management system" with 27 tables that you never finish.
Build these projects in order. Each adds a new SQL skill, and each is small enough to finish between classes.
Set up once, then keep everything
SQLite works well here because your whole database lives in one file. No server setup is needed before you can write your first query. When you're unsure about the syntax, check its SELECT documentation instead of guessing and hoping the database agrees.
Keep four files for every project: schema.sql for tables, data.sql for sample rows, queries.sql for your answers and README.md for assumptions.
Then make the data awkward on purpose. Add two students with the same name, an expense paid on a Sunday and a book returned late. Perfect data hides half your mistakes. A query can look correct for weeks when every name is unique and every total comes out neatly.
1. Hostel expense tracker: learn grouping properly
Start with one expenses table. Give it an expense ID, payer name, item, amount and payment date. Add around a dozen rows, including two expenses with the same amount and one item name written in two different cases.
Try these questions:
- How much did each student pay?
- Which expenses cost more than the average expense?
- On which dates was more than one expense recorded?
- Who paid the most, and what happens when two students tie?
The first answer looks harmless:
SELECT payer_name, SUM(amount) AS total_paid
FROM expenses
GROUP BY payer_name
ORDER BY total_paid DESC;
One row here means one payer. SUM(amount) adds that payer's rows, and the descending order puts the biggest contribution first.
The common beginner error is selecting item too:
SELECT payer_name, item, SUM(amount) AS total_paid
FROM expenses
GROUP BY payer_name;
SQLite may return an item without complaining, but which item should it pick when the payer bought several? Your result is about payers, so every selected value should be either the payer or a value calculated for that whole group. This is annoying because the output still looks neat. Neat output can still be nonsense.
For the average question, use a subquery:
SELECT item, amount
FROM expenses
WHERE amount > (SELECT AVG(amount) FROM expenses);
The inner query calculates one average across all expenses. The outer query then compares each row with that number.
For dates with multiple expenses, group by payment_date and add HAVING COUNT(*) > 1. Using WHERE COUNT(*) > 1 won't work because the groups don't exist yet when WHERE runs.
Now write a balance query comparing each payer's contribution with an equal share of the total:
WITH payer_totals AS (
SELECT payer_name, SUM(amount) AS total_paid
FROM expenses
GROUP BY payer_name
)
SELECT payer_name,
total_paid,
ROUND(
total_paid -
(SELECT SUM(total_paid) FROM payer_totals) /
(SELECT COUNT(*) FROM payer_totals),
2
) AS balance
FROM payer_totals;
A positive balance means the student paid more than an equal share. A negative balance means they paid less. Also check your top-payer query with a tie. ORDER BY total_paid DESC can show both students, while adding LIMIT 1 silently picks only one.
That balance step turns a totals exercise into something you can actually discuss.
2. College library loans: make joins mean something
Now use three tables: students``books and loans. A loan stores the student ID, book ID, issue date, due date and return date. Leave return_date empty while the book is still out. In SQL, that empty value should be NULLnot the text 'NULL'.
Your questions:
- List every loan with the student's name and book title.
- Find books that have never been borrowed.
- Show loans still open on a fixed date you choose.
- Count loans per student, including students with none.
That last question catches people out. An inner join quietly removes students who have no loans, so start from students and use a left join:
SELECT s.student_name, COUNT(l.loan_id) AS loan_count
FROM students AS s
LEFT JOIN loans AS l ON l.student_id = s.student_id
GROUP BY s.student_id, s.student_name
ORDER BY loan_count DESC;
Use COUNT(l.loan_id)not COUNT(*). With no matching loan, the left join still produces one row for the student, with the loan columns set to NULL. COUNT(*) counts that row and reports one loan that doesn't exist. COUNT(l.loan_id) ignores the NULL and correctly returns zero.
SQL has no embarrassment about giving you a confident, wrong answer.
For books never borrowed, start with booksleft join loans on the book ID and keep rows where l.loan_id IS NULL. For open loans on your chosen date, check that the issue date is on or before that date. Then require the return date to be NULL or later than that date.
For overdue books, compare dates with a fixed value such as '2025-03-31' rather than today's date. Your results will stay repeatable when you show the project later. Otherwise, the same query changes its answer overnight and your expected output in the README becomes wrong.
3. Canteen orders: query data at two levels
An order and the items inside it are different things. Model them separately with orders and order_items. The item rows should include order ID, item name, quantity and unit price.
Ask yourself:
- What is the value of each order?
- Which item sold the greatest total quantity?
- What is the average order value?
- Which orders contain both tea and samosas?
Calculate order totals first:
SELECT order_id,
SUM(quantity * unit_price) AS order_value
FROM order_items
GROUP BY order_id;
One row in this result means one order. quantity * unit_price calculates the value of each item line, and SUM combines the lines belonging to that order.
To get the average order value, put that grouped query inside another query:
WITH order_totals AS (
SELECT order_id, SUM(quantity * unit_price) AS order_value
FROM order_items
GROUP BY order_id
)
SELECT AVG(order_value) AS average_order_value
FROM order_totals;
Averaging quantity * unit_price directly would average item lines, which is a different question. An order with five lines would affect that answer more heavily than an order with one line.
For tea-and-samosa orders, group by order ID and use conditional counts in HAVING:
SELECT order_id
FROM order_items
GROUP BY order_id
HAVING SUM(CASE WHEN item_name = 'tea' THEN 1 ELSE 0 END) > 0
AND SUM(CASE WHEN item_name = 'samosa' THEN 1 ELSE 0 END) > 0;
Add an order containing tea twice and no samosa. It quickly shows whether your condition checks both products or merely counts rows. A condition such as HAVING COUNT(*) >= 2 would wrongly accept that tea-only order.
Also decide what happens when the same item appears twice in one order. Do you combine the lines, reject the duplicate or allow it? There's no universal business rule here. Write your choice in the README.
4. Attendance reports: handle percentages and edge cases
Create students``sessions and attendance. Each attendance row connects a student to a class session and has a status such as present or absent.
Practise with these questions:
- Calculate each student's attendance percentage.
- List students below a cut-off you choose.
- Find sessions with no attendance records.
- Find students marked present twice for the same session.
A percentage query can use CASE:
SELECT student_id,
ROUND(
100.0 * SUM(CASE WHEN status = 'present' THEN 1 ELSE 0 END)
/ COUNT(*),
2
) AS attendance_percentage
FROM attendance
GROUP BY student_id;
CASE turns each present row into 1 and every other row into 0. The sum is therefore the number of present rows. Multiplying by 100.0 before dividing gives you a percentage, and ROUND limits it to two decimal places.
Before celebrating, test a student with no attendance rows. This query won't include that student at all. Should the report show zero, blank or leave the student out? State that decision. If every student must appear, start from students and use a left join, then decide how to handle the missing count.
Then test a session with two rows for one student:
SELECT student_id, session_id
FROM attendance
WHERE status = 'present'
GROUP BY student_id, session_id
HAVING COUNT(*) > 1;
If duplicate rows reach the percentage query, they can change both the numerator and denominator. Your percentage may suddenly become creative accounting.
This project is good HAVING practice too. To show students below your chosen cut-off, repeat the attendance calculation as an expression in HAVING and compare it with that cut-off. Filter grouped results with HAVING; use WHERE for rows before grouping. Mixing those up is one of those small errors our trainers see all the time.
For sessions with no attendance records, start from sessionsleft join attendance using the session ID and look for a NULL attendance ID.
5. Event registrations: finish with window functions
Build events and registrations. Events have a seat limit. Registrations have a student ID, event ID and registration time. Include more registrations than seats for one event, or your seat-limit query will pass without really being tested.
Your final questions:
- How many seats remain in each event?
- Who made it inside the seat limit, based on registration time?
- Which students registered for the same event twice?
- What is each student's earliest registration across all events?
A window function lets you number registrations without collapsing them into one row per event. SQLite documents this syntax on its window functions page.
WITH ranked AS (
SELECT r.*,
ROW_NUMBER() OVER (
PARTITION BY event_id
ORDER BY registered_at, registration_id
) AS position
FROM registrations AS r
)
SELECT ranked.student_id, ranked.event_id
FROM ranked
JOIN events AS e ON e.event_id = ranked.event_id
WHERE ranked.position <= e.seat_limit;
PARTITION BY event_id restarts the numbering for each event. The ordering puts earlier registrations first. Unlike GROUP BYthe window keeps every registration row available for the final filter.
Notice the second sort key. If two registrations have the same time, registration_id gives the database a clear tie-breaker. Without one, deciding who gets the last seat can feel suspiciously like vibes.
For seats remaining, count registrations per event and subtract that count from the seat limit. Decide whether to show a negative number for an overbooked event or display zero. For duplicate registrations, group by student ID and event ID, then keep groups with HAVING COUNT(*) > 1. For each student's earliest registration, group by student ID and select MIN(registered_at).
Make the work easy to inspect
Put all five projects in one repository with a short contents page. For each query, write the question above it and include a few expected output rows in the README. This makes checking much faster than rerunning everything and trying to remember what looked right last week.
If a query returns nothing, say whether that's correct. An empty result often means the join condition is wrong, but nobody reviewing your files can read your mind. For example, a query for books never borrowed may correctly return nothing after every book has a loan. That same empty result would be suspicious if your sample data includes an untouched book.
When you practise explaining one project, point to the grain of the result: one row per student, per order or per registration. Then explain the join and one weird test row. That's far more useful than reciting what GROUP BY means.
If you want guided practice after these projects, our SQL Training course is a way to go deeper with the same querying ideas.
Start with the expense tracker today. Twelve messy rows and four answered questions will give you a better beginning than another beautifully named, empty repository.
3 questions, about a minute
Check your understanding
- SQL
- Student projects
- Internships
- Databases
- Programming
