Introduction
Excel is the go-to tool in schools for managing student records, attendance, and exam scores. But when your Excel files grow large and complex, formulas fall short. That’s where SQL in Excel comes in. You can use SQL to filter, join, and analyze Excel data without writing complex macros — right from within your spreadsheet.
Step 1: Prepare Your Excel Sheet
Let’s say you have a sheet named students:
| roll_no | name | class | city |
|---------|------------|-------|-----------|
| 1 | Aarav | 10A | Pune |
| 2 | Diya | 10A | Chennai |
| 3 | Sneha | 9B | Mumbai |
- Save the file as `.xlsx`
- Make sure the first row has column headers
- Name the sheet **students** or assign a named range (recommended)
Step 3: Run SQL Queries on Excel Table
Instead of loading the full table, click Home → Advanced Editor in Power Query and modify the code using SQL-like syntax.
Example: Select students from class 10A
let
Source = Excel.Workbook(File.Contents("C:\Users\You\Documents\school.xlsx"), null, true),
Students_Sheet = Source{[Item="students",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Students_Sheet, [PromoteAllScalars=true]),
#"Filtered Rows" = Table.SelectRows(#"Promoted Headers", each ([class] = "10A"))
in
#"Filtered Rows"
roll_no | name | class | city
--------+--------+-------+---------
1 | Aarav | 10A | Pune
2 | Diya | 10A | Chennai
Step 4: Using Microsoft Query (Legacy Method)
Alternatively, use Microsoft Query to run SQL:
- Go to Data → Get Data → From Other Sources → From Microsoft Query
- Choose "Excel Files" as the data source
- Select your workbook
- Write SQL like:
SELECT name, city FROM [students$] WHERE class = '9B';
Step 5: Connect to External SQL Database via Excel
- Go to Data → Get Data → From Database → From MySQL/SQL Server
- Enter server details, authentication, and database name
- Select the table and load or transform with Power Query
This is useful when your student data is stored in a centralized MySQL database on a server.
Summary
With just Excel and a bit of SQL, you can unlock powerful data filtering and transformation — no coding or VBA required. Whether you’re preparing student reports, filtering city-wise performance, or pulling term-wise data from school systems, SQL with Excel makes it efficient, scalable, and reusable.
What’s Next?
Coming up: SQL Interview Questions — a practical dive into real-world SQL challenges faced in education and business contexts.

About the authorSrinivas Namala
Software Engineer
Srinivas focuses on backend development, databases, systems, and the technologies used to build reliable server-side applications.
View LinkedIn profile ↗