






SQL with Excel
Query Your School Data Without Leaving Excel
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.
Why Use SQL with Excel?
- Query multiple sheets like tables
- Run SELECT, WHERE, JOIN, and GROUP BY inside Excel
- Build dynamic dashboards without VBA
- Connect external databases (MySQL, Access) via Excel
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 2: Load Data Using Power Query
For Excel 2016 or later:
- Go to Data → Get & Transform Data → Get Data → From Workbook
- Select the Excel file
- Choose the
students
sheet or named range - Click Transform Data to open Power Query Editor
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.
Real-World School Use Cases
- Generate attendance reports from Excel with SQL filters
- Create pivot-style summaries using
GROUP BY
- Merge student and marks sheets using
JOIN
-like operations - Feed SQL-transformed Excel tables into Power BI
Tips and Best Practices
- Name your tables/ranges clearly
- Avoid merged cells — SQL hates them
- Use Power Query instead of formulas for better scalability
- Save a backup before applying SQL transformations
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.