Ravindra BagaleCourses & study guides मराठी Track your progress

Guides

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

  1. Turn your data into an Excel table (Ctrl+T) and give it a name such as Orders. That is your FROM.
  2. Use SUMIFS / COUNTIFS / AVERAGEIFS for WHERE plus an aggregate.
  3. Use a PivotTable (or SUMIFS by category) for GROUP BY.
  4. Use XLOOKUP with an if_not_found value for a LEFT JOIN, or Power Query Merge Queries for bigger joins.
  5. Use FILTER, SORT and UNIQUE for WHERE, ORDER BY and DISTINCT that return rows.
  6. 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.

SQLExcel (menus)Excel (formulas)
SELECT col1, col2Pick or hide columns; in formulas, refer to the columns you needTable columns, CHOOSECOLS
FROM OrdersAn Excel table (Ctrl+T) named OrdersStructured references such as Orders[Amount]
WHERE City = 'Pune'Filter button on the City columnFILTER, or SUMIFS/COUNTIFS conditions
AND / ORSeveral filters / Custom Filter(cond1)*(cond2) for AND, (cond1)+(cond2) for OR inside FILTER
ORDER BY Amount DESCSort Largest to SmallestSORT, SORTBY, LARGE
LIMIT 3 / TOP 3Top 10 filter set to 3TAKE, or LARGE with 1, 2, 3
DISTINCTRemove DuplicatesUNIQUE
GROUP BY City with SUM / COUNT / AVGPivotTableSUMIFS, COUNTIFS, AVERAGEIFS, GROUPBY
HAVING SUM(Amount) > 5000Value filter on a PivotTableFILTER on the summary
LEFT JOIN CustomersPower Query Merge Queries (Left Outer)XLOOKUP with an if_not_found value
INNER JOINPower Query Merge Queries (Inner)FILTER rows where COUNTIF finds a match
UNION ALLPower Query Append QueriesVSTACK
CASE WHEN ... THEN ... END-IF, IFS, SWITCH
LIKE '%Roast%'Text Filters > ContainsWildcards in COUNTIFS ("*Roast*"), SEARCH
NULL / IS NULLBlank 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 VIEWA 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.

QuestionSQLExcelAnswer
Total sales in PuneSELECT SUM(Amount) FROM Orders WHERE City = 'Pune';=SUMIFS(Orders[Amount],Orders[City],"Pune")₹10,700
Average order in KolhapurSELECT AVG(Amount) FROM Orders WHERE City = 'Kolhapur';=AVERAGEIFS(Orders[Amount],Orders[City],"Kolhapur")₹1,300
Number of different customersSELECT COUNT(DISTINCT Customer) FROM Orders;=COUNTA(UNIQUE(Orders[Customer]))8
Orders for a 'Roast' productSELECT COUNT(*) FROM Orders WHERE Product LIKE '%Roast%';=COUNTIFS(Orders[Product],"*Roast*")5
Largest orderSELECT 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)
CitySalesOrders
Kolhapur₹3,9003
Nagpur₹6,4404
Nashik₹4,7004
Pune₹10,7008
Solapur₹5,8005

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 quicklyThe same query must run every day on fresh data
The audience opens files, not databasesMany people need the same, controlled numbers
You need what-if inputs next to the numbersYou 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.

Practice task

  1. On Side by side, change "Pune" to "Nashik" in the first formula and write the matching SQL.
  2. Write the Excel version of SELECT COUNT(*) FROM Orders WHERE Qty >= 3;.
  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.
  4. Add a column to Orders that brings the customer's city from the Customers table with XLOOKUP. Which order shows (no match)?
  5. Write SELECT Product, SUM(Qty) FROM Orders GROUP BY Product with 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.