SQL vs Excel: What Is the Difference?
By Owen Middleton · Updated November 2026 · We ran the examples on PostgreSQL 17
SQL is a language that you use to get and change data in a database. Excel is a spreadsheet program where you see your data in cells and work on it with formulas.
In our view, learn first the tool where your data is now. If you want a data job, plan to learn both.
We make SQLMaxx Learn, a free SQL course. We teach no Excel, so we have an interest in the SQL half of this answer.
How do SQL and Excel store and query data?
In SQL, the data is in tables in a database. You write a query, and the database engine gives you only the result.
- Where the data is. SQL: In tables in a database. Excel: In cells on a worksheet, or in the Data Model.
- How you ask a question. SQL: You write one query. Excel: You write a formula and fill it down, or you use a PivotTable.
- What you see. SQL: The result of the query. The table stays separate. Excel: Your data and your formulas, in cells of the workbook.
- How much data. SQL: PostgreSQL: no fixed row limit. The size limit for one relation (for example, one table) is 32 TB, with the default block size. (PostgreSQL 17 documentation) Excel: Rows on one worksheet: 1,048,576. (Microsoft)
What does one question look like in SQL and in Excel?
Here is one question about Helix Systems, a sample company: how many active employees does each department
have? The data is in two tables, employees and departments. Each employee has a
department_id, and is_active is true or false.
Schema · hr2 tables? = nullable
For the Excel version, put the same data in two Excel tables, Employees and
Departments (Microsoft: Excel tables). On a
third sheet, type the 8 department names in cells A2 to A9. Make sure that is_active has
the values TRUE and FALSE, not text. We did not run the Excel formulas on this page, so check the result in
your own workbook.
SQL (PostgreSQL)
SELECT d.name AS department, COUNT(*) AS active_employees
FROM employees e
JOIN departments d ON d.id = e.department_id
WHERE e.is_active
GROUP BY d.name
ORDER BY active_employees DESC, d.name; | department | active_employees |
|---|---|
| Engineering | 16 |
| Sales | 9 |
| Product | 7 |
| Data | 6 |
| Marketing | 5 |
| Support | 5 |
| Finance | 4 |
| HR | 4 |
Excel
Excel formulas. Shown as an example. Not run on this page.
Cell B2, then fill down to B9:
=COUNTIFS(
Employees[department_id],
XLOOKUP(A2, Departments[name], Departments[id]),
Employees[is_active], TRUE
)
Then sort the rows by column B, largest first,
and then by column A.In Excel, you type one formula in B2 and fill it down to the other cells of the answer. In SQL, you write one query, and PostgreSQL gives you all 8 rows. In Excel, you can also get this count with a PivotTable (Microsoft Support, Create a PivotTable).
You also find the department in a different way in each version:
- In Excel, you use XLOOKUP to find the department id for each name, one cell at a time. Then you use COUNTIFS to count the rows that meet both criteria.
- In SQL, you use one
JOINto connect each employee to a department, for all rows at the same time.
Employees[department_id] is a structured reference: the name of a table and the name of a column. When you fill the
formula down, the structured references stay the same (Microsoft: "There is no column specifier adjustment.",
in Using structured references with Excel tables). Microsoft also writes that
XLOOKUP "is not available in Excel 2016 and Excel 2019".
Change the SQL query below, and then run it. For example, remove the WHERE line to count all employees.
SELECT d.name AS department, COUNT(*) AS active_employees FROM employees e JOIN departments d ON d.id = e.department_id WHERE e.is_active GROUP BY d.name ORDER BY active_employees DESC, d.name;
To write queries like this one, start with the free GROUP BY lesson.
Here is a second question: how many people had Helix Systems hired by the end of each year?
SQL (PostgreSQL)
SELECT hire_year, hires, SUM(hires) OVER (ORDER BY hire_year) AS hired_to_date
FROM (
SELECT EXTRACT(YEAR FROM hire_date)::int AS hire_year, COUNT(*) AS hires
FROM employees
GROUP BY 1
) AS y
ORDER BY hire_year; | hire_year | hires | hired_to_date |
|---|---|---|
| 2018 | 5 | 5 |
| 2019 | 9 | 14 |
| 2020 | 13 | 27 |
| 2021 | 21 | 48 |
| 2022 | 12 | 60 |
Excel
Excel formulas. Shown as an example. Not run on this page.
Column A: the year. Column B: the hires in that year.
Cell C2, then fill down to C6:
=SUM($B$2:$B2)
We follow Microsoft's pattern for this formula, from
Calculate a running total in Excel. When you fill
the formula down, the first cell, $B$2, stays the same. The second cell becomes $B3, then $B4, and so on. In SQL, with SUM(hires) OVER (ORDER BY hire_year), you add each year to the years before
it, in one query. To learn
this type of query, see the Running Totals and Cumulative Metrics lesson.
When is Excel a better choice than SQL?
In our view, Excel is often the better tool. Use Excel for these tasks:
- Small data that you type in yourself.
- A quick chart of the data on a sheet.
- A summary with a PivotTable. With a PivotTable, you summarize data by group (Microsoft Support, Create a PivotTable).
- A what-if question: you change the value in one cell, and you see the new totals. Automatic calculation is "the default calculation setting" (Microsoft Support, Change formula recalculation).
- A file for a colleague who does not know SQL.
When is SQL a better choice than Excel?
In our view, use SQL for these tasks:
- Data that is already in a database. You ask the database for the rows. You do not copy them into a sheet.
- More than 1,048,576 rows, the row limit of one Excel worksheet.
-
Data in two or more related tables. You write one
JOIN, as in the example above. In the Excel example, you use a lookup in each row. - A question that you ask each week. You run the same query again. Save the query, and you have a record of each step. In Excel, you can also repeat a task with Power Query. Microsoft writes: "When you refresh a query, each step runs automatically." (Microsoft Support, About Power Query in Excel)
Is SQL in Excel?
Excel formulas, for example COUNTIFS and XLOOKUP above, are not SQL. But you can send a SQL query from Excel to a database with Power Query.
Microsoft writes that Power Query "can run native database queries" (Microsoft Learn, Import data from a database using native database query). When you connect to a database, you type the query in a text box under Advanced options. In the list of connectors on that page, Microsoft gives the type "SQL statement" for PostgreSQL. In Excel, Get Data is on the Data tab (Microsoft Support, About Power Query in Excel).
You must have a database to connect to. With Power Query, you send the query to a database. You do not type SQL in a cell.
Should you learn SQL or Excel first?
In our view, start with the tool where your data is now. If your work data is in spreadsheets, start with Excel. If it is in a database, or you want a data job where employers ask for SQL, start with SQL.
Can you learn SQL without Excel? Yes. For SQLMaxx Learn lesson 1, you need only a web browser.
Can you learn Excel and SQL at the same time? Yes. In our view, you can use what you learn in one tool when you learn the other. A SQL table is like a sheet where each column has a name and one data type.
If you also think about Python, read should you learn SQL or Python first.
Start SQLMaxx Learn lesson 1
SQLMaxx Learn is a free SQL course in 66 lessons. Lesson 1 is "SELECT and Column Expressions". You can start it in your browser with no account.
You write each query in a real PostgreSQL database and get a check of your result, but you learn only PostgreSQL, and there is no Excel content.
For all 66 lessons in order, see SQL from beginner to advanced.
More questions about SQL and Excel
Which is harder, SQL or Excel?
In our view, neither is hard for a first task. In Excel, you can add up a column of numbers with the AutoSum button on the Home tab. In SQL, you type your first query as text, for example one line with SELECT and FROM. Source: Microsoft Support, Use AutoSum to sum numbers. Read more about how hard SQL is.
Is Excel basically SQL?
No. In both, you work with rows and columns. But when you use Excel tables and formulas in one workbook, your data and your formulas are in cells of that workbook. A SQL query is text that is separate from the table. When you run a SELECT query like the queries on this page, the table stays the same.
Can I learn SQL in Excel?
Not easily. With Power Query, you can send a SQL query from Excel to a database, but you must have a database first. In our view, a SQL editor with a database is the shorter path.