Excel vs SQL: Term-by-Term Mapping with Side-by-Side Examples
Raja Coffee Roasters keeps its orders in an Excel table. The owner asks Shraddha, the analyst: "What did Pune buy?" A SQL user types SELECT SUM(Amount) FROM Orders WHERE City = 'Pune';. An Excel user types =SUMIFS(Orders[Amount],Orders[City],"Pune"). Both get ₹10,700. The two tools ask the same questions in different words. Learn the word pairs and you can move between them.
SQL and Excel answer the same questions. WHERE is a filter or the condition part of SUMIFS and FILTER; GROUP BY is a PivotTable or SUMIFS by category (GROUPBY in Microsoft 365); JOIN is XLOOKUP or Power Query Merge; ORDER BY is SORT; DISTINCT is UNIQUE; CASE WHEN is IF or IFS. Use Excel for quick, visual analysis of data that fits in a sheet, and SQL when the data lives in a database or is too big for a sheet.
Download the practice file (vs-sql.xlsx)
Excel file, 12 KB. It has the sample data used below. All numbers in this workbook are fictional teaching data, not real company figures.
Quick answer
- Turn your data into an Excel table (Ctrl+T) and give it a name such as Orders. That is your FROM.
- Use SUMIFS / COUNTIFS / AVERAGEIFS for WHERE plus an aggregate.
- Use a PivotTable (or SUMIFS by category) for GROUP BY.
- Use XLOOKUP with an if_not_found value for a LEFT JOIN, or Power Query Merge Queries for bigger joins.
- Use FILTER, SORT and UNIQUE for WHERE, ORDER BY and DISTINCT that return rows.
- Use IF / IFS for CASE WHEN.
The term-mapping table
Read across each row: the SQL clause, the Excel menu way, and the Excel formula way.
| SQL | Excel (menus) | Excel (formulas) |
|---|---|---|
| SELECT col1, col2 | Pick or hide columns; in formulas, refer to the columns you need | Table columns, CHOOSECOLS |
| FROM Orders | An Excel table (Ctrl+T) named Orders | Structured references such as Orders[Amount] |
| WHERE City = 'Pune' | Filter button on the City column | FILTER, or SUMIFS/COUNTIFS conditions |
| AND / OR | Several filters / Custom Filter | (cond1)*(cond2) for AND, (cond1)+(cond2) for OR inside FILTER |
| ORDER BY Amount DESC | Sort Largest to Smallest | SORT, SORTBY, LARGE |
| LIMIT 3 / TOP 3 | Top 10 filter set to 3 | TAKE, or LARGE with 1, 2, 3 |
| DISTINCT | Remove Duplicates | UNIQUE |
| GROUP BY City with SUM / COUNT / AVG | PivotTable | SUMIFS, COUNTIFS, AVERAGEIFS, GROUPBY |
| HAVING SUM(Amount) > 5000 | Value filter on a PivotTable | FILTER on the summary |
| LEFT JOIN Customers | Power Query Merge Queries (Left Outer) | XLOOKUP with an if_not_found value |
| INNER JOIN | Power Query Merge Queries (Inner) | FILTER rows where COUNTIF finds a match |
| UNION ALL | Power Query Append Queries | VSTACK |
| CASE WHEN ... THEN ... END | - | IF, IFS, SWITCH |
| LIKE '%Roast%' | Text Filters > Contains | Wildcards in COUNTIFS ("*Roast*"), SEARCH |
| NULL / IS NULL | Blank cells / filter (Blanks) | ISBLANK, COUNTBLANK |
| COALESCE(a, b) | - | IF(a="",b,a), IFERROR for errors |
| SUM() OVER (ORDER BY Date) | - | Running total =SUM($G$2:G2) |
| CREATE VIEW | A saved Power Query query | - |
Function availability
FILTER, SORT, UNIQUE and XLOOKUP need Excel 2021, Excel 2024 or Microsoft 365; Microsoft's XLOOKUP page says it is not available in Excel 2016 and Excel 2019. GROUPBY is listed for Excel for Microsoft 365. TAKE, VSTACK and CHOOSECOLS are newer dynamic-array functions; check each function's page on Microsoft Support for your version.
Side-by-side examples
All examples use the same Orders table (24 orders) and Customers table (7 customers) in the practice file. We ran every SQL query in SQLite on the same rows and checked that Excel returns the same answer.
| Question | SQL | Excel | Answer |
|---|---|---|---|
| Total sales in Pune | SELECT SUM(Amount) FROM Orders WHERE City = 'Pune'; | =SUMIFS(Orders[Amount],Orders[City],"Pune") | ₹10,700 |
| Average order in Kolhapur | SELECT AVG(Amount) FROM Orders WHERE City = 'Kolhapur'; | =AVERAGEIFS(Orders[Amount],Orders[City],"Kolhapur") | ₹1,300 |
| Number of different customers | SELECT COUNT(DISTINCT Customer) FROM Orders; | =COUNTA(UNIQUE(Orders[Customer])) | 8 |
| Orders for a 'Roast' product | SELECT COUNT(*) FROM Orders WHERE Product LIKE '%Roast%'; | =COUNTIFS(Orders[Product],"*Roast*") | 5 |
| Largest order | SELECT MAX(Amount) FROM Orders; | =MAX(Orders[Amount]) | ₹3,200 |
| Orders that match a customer (INNER JOIN count) | SELECT COUNT(*) FROM Orders o JOIN Customers c ON o.Customer = c.Customer; | =SUMPRODUCT(--(COUNTIF(Customers[Customer],Orders[Customer])>0)) | 22 |
GROUP BY and HAVING
-- SQL
SELECT City, SUM(Amount) AS Sales, COUNT(*) AS Orders
FROM Orders
GROUP BY City
HAVING SUM(Amount) > 5000;
' Excel (one row per city)
Sales =SUMIFS(Orders[Amount],Orders[City],A14)
Orders =COUNTIFS(Orders[City],A14)
HAVING =FILTER(A14:A18,B14:B18>5000)
| City | Sales | Orders |
|---|---|---|
| Kolhapur | ₹3,900 | 3 |
| Nagpur | ₹6,440 | 4 |
| Nashik | ₹4,700 | 4 |
| Pune | ₹10,700 | 8 |
| Solapur | ₹5,800 | 5 |
Cities with sales above ₹5,000: Nagpur, Pune, Solapur. In a PivotTable, the same HAVING is Row Labels > Value Filters > Greater Than. In Microsoft 365 you can also write =GROUPBY(Orders[City],Orders[Amount],SUM).
JOIN = XLOOKUP (and Power Query Merge)
A LEFT JOIN keeps every order and brings the customer's segment when there is a match. XLOOKUP does the same, one row at a time:
-- SQL
SELECT o.OrderID, c.Segment
FROM Orders o LEFT JOIN Customers c ON o.Customer = c.Customer;
' Excel, in a new column of Orders
=XLOOKUP(C2,Customers[Customer],Customers[Segment],"(no match)")
Ruhi is in Orders but not in Customers. SQL returns NULL for her segment; the XLOOKUP returns "(no match)" because we gave it that as the fourth argument. An INNER JOIN would keep only the 22 orders that match. For joins on many columns or large tables, use Data > Get Data > Combine Queries > Merge in Power Query and pick the join kind (Left Outer, Inner, Full Outer and so on).
WHERE that returns rows, ORDER BY and LIMIT
-- SQL
SELECT OrderID FROM Orders WHERE City = 'Pune' AND Amount >= 1000;
SELECT Amount FROM Orders ORDER BY Amount DESC LIMIT 3;
' Excel
=FILTER(Orders[Order ID],(Orders[City]="Pune")*(Orders[Amount]>=1000))
=LARGE(Orders[Amount],1) then 2 and 3
=TAKE(SORT(Orders[Amount],,-1),3) (Microsoft 365)
The FILTER returns orders 1006, 1011, 1012, 1020, 1021, 1024. Multiplying the two conditions means AND; adding them means OR. The three largest orders are ₹3,200, ₹2,100, ₹1,920.
CASE WHEN and window functions
-- SQL
SELECT OrderID,
CASE WHEN Amount >= 1500 THEN 'Large' WHEN Amount >= 800 THEN 'Medium' ELSE 'Small' END AS Size,
SUM(Amount) OVER (ORDER BY Date) AS RunningTotal
FROM Orders;
' Excel
=IFS(G2>=1500,"Large",G2>=800,"Medium",TRUE,"Small")
=SUM($G$2:G2)
The running total uses a range that grows as you fill down: the start is locked with $, the end moves. That is what SQL's window function does in one line.
When to use which
| Use Excel when... | Use SQL when... |
|---|---|
| The data fits comfortably in a sheet (Microsoft's limit is 10,48,576 rows by 16,384 columns per worksheet) | The data lives in a database or is too large for a sheet |
| You want to explore, chart and share quickly | The same query must run every day on fresh data |
| The audience opens files, not databases | Many people need the same, controlled numbers |
| You need what-if inputs next to the numbers | You need to join many large tables |
Many analysts use both: SQL to pull a clean extract, Excel (or Power Query connected to the database) to analyse and present it.
Ravindra Bagale's Tip
Write the question in plain words first, then translate it. 'Total sales by city where sales are above 5,000' turns into GROUP BY + HAVING in SQL, or SUMIFS + FILTER in Excel. If you cannot say the question in one sentence, neither tool will save you.
Ravindra Bagale's Tip – मराठी
आधी प्रश्न साध्या शब्दांत लिहा, मग त्याचे भाषांतर करा. 'ज्या cities ची sales 5,000 पेक्षा जास्त आहे त्यांची एकूण sales' म्हणजे SQL मध्ये GROUP BY + HAVING, आणि Excel मध्ये SUMIFS + FILTER. प्रश्न एका वाक्यात सांगता येत नसेल तर कोणतेही tool मदत करणार नाही.
Ravindra Bagale's Tip – हिंदी
पहले सवाल सीधे शब्दों में लिखिए, फिर उसका अनुवाद कीजिए। 'जिन cities की sales 5,000 से ज़्यादा है उनकी कुल sales' मतलब SQL में GROUP BY + HAVING, और Excel में SUMIFS + FILTER। अगर सवाल एक वाक्य में नहीं कह पा रहे, तो कोई भी tool मदद नहीं करेगा।
Practice task
- On Side by side, change "Pune" to "Nashik" in the first formula and write the matching SQL.
- Write the Excel version of
SELECT COUNT(*) FROM Orders WHERE Qty >= 3;. - Build a PivotTable with City in Rows and Sum of Amount in Values, then add a Value Filter for 'greater than 5000' and compare it with the HAVING result.
- Add a column to Orders that brings the customer's city from the Customers table with XLOOKUP. Which order shows (no match)?
- Write
SELECT Product, SUM(Qty) FROM Orders GROUP BY Productwith SUMIFS.
Learn it properly
Course lessons:
- 3.2 SUM, SUMIF and SUMIFS
- 4.6 XLOOKUP Basics and if_not_found
- 9.4 UNIQUE
- 7.1 Creating a PivotTable
- 10.5 Merge Queries
Related guides: Excel vs Python pandas: Same Tasks Side by Side, and When to Use Each · VLOOKUP vs XLOOKUP vs INDEX-MATCH: Which Lookup Should You Use? · PivotTable vs GROUPBY and PIVOTBY: Which Should You Use in Excel? · SUMIF and SUMIFS
Frequently asked questions
Is Excel a database?
No. Excel is a spreadsheet. It can hold table-like data and answer database-style questions, but it does not enforce data types, relationships or multi-user transactions the way a database does.
Can Excel run SQL?
Not in worksheet formulas. Power Query can connect to databases such as SQL Server and can run a native SQL query against them, and you can load the result into a sheet.
What is the Excel equivalent of GROUP BY?
A PivotTable, or SUMIFS/COUNTIFS/AVERAGEIFS with one row per group. In Excel for Microsoft 365, the GROUPBY function does it in one formula.
What is the Excel equivalent of a JOIN?
XLOOKUP for bringing one column from another table (like a LEFT JOIN), or Power Query Merge Queries for full joins with a choice of join kind.