SQL Practice Questions for Students, With Sample Data
The fastest way to learn SQL is to run queries on data you can see. Here is a student table and ten queries to try.
Generate a Students dataset in the box below and download it as CSV. Then open SQL on Your Files and drop in the file. The table takes the name of the file, so students.csv becomes a table called students. The columns are student_id, full_name, email, course, year, marks, attendance_pct, city and enrolled_on.
Start simple. 1) SELECT * FROM students LIMIT 10; 2) SELECT full_name, marks FROM students WHERE marks >= 80; 3) SELECT * FROM students ORDER BY marks DESC LIMIT 5; 4) SELECT COUNT(*) FROM students; 5) SELECT DISTINCT course FROM students.
Then summarise. 6) SELECT course, AVG(marks) AS average_marks FROM students GROUP BY course; 7) SELECT course, COUNT(*) FROM students GROUP BY course HAVING COUNT(*) > 20; 8) SELECT year, MAX(marks) FROM students GROUP BY year ORDER BY year; 9) SELECT * FROM students WHERE attendance_pct < 75 AND marks < 50.
For JOIN, generate the Exam marks dataset too, save it as marks.csv and load both files. Then try: SELECT s.full_name, m.subject, m.marks FROM students s JOIN marks m ON s.student_id = m.student_id LIMIT 20. The student ids in the two datasets are random, so few rows will match; to practise joins that match, use a small file you write yourself or a table you create from the SQL Generator.
Everything runs in your browser and nothing is uploaded.
Related tool pages
- Query a Large CSV with SQL: Run SQL on a CSV of 500 MB or more without a database. Filter, group and export the result. Runs in your browser.
- Query a CSV File with SQL: Query a CSV file with SQL online. Filter, group, sort and join with DuckDB in your browser. No database, no install and no upload.
- Run SQL on an Excel File: Run SQL queries on an Excel file without importing it into a database. Join sheets from different files and download the result.
- Query Parquet Files Online: Open and query Parquet files with SQL in your browser. Preview, filter, aggregate and export to CSV without installing anything.
- Join CSV Files with SQL: Join two or more CSV files with SQL JOIN: inner, left, right or full. Runs in your browser with DuckDB and nothing is uploaded.
- DuckDB in Your Browser: Use DuckDB in your browser with no setup. Drop in CSV, Excel, JSON or Parquet files and run analytical SQL on your own computer.
How to use the SQL on Your Files: step by step
- Generate the Students dataset and download CSV.
- Open SQL on Your Files and drop in the file.
- Run the queries one by one and change them.
- Try your own questions about courses and marks.
When to use the SQL on Your Files
- Learn SELECT, WHERE and ORDER BY
- Practise GROUP BY and HAVING
- Prepare for a DBMS exam
- Test a query before using it on real data
Example
Input: sales.csv + customers.xlsx
Output: SQL query result
Frequently asked questions
Can I run SQL on a CSV file?
Yes. Add the file, write a query such as SELECT * FROM sales WHERE amount > 100 and click Run. It runs in your browser with DuckDB.
Is this an alternative to DBeaver or TablePlus?
For querying files, yes. You do not need to install anything or create a database. For connecting to a live database server, use a database client.
Which SQL does it use?
DuckDB SQL, which is close to PostgreSQL. Joins, aggregates, window functions, CTEs and date functions all work.
Does it work offline?
Not the first time, because the SQL engine is downloaded when you first run a query.
Tip: Change one thing at a time in a query and run it again. That is how SQL sticks.