Run SQL Queries in Excel: A Step-by-Step Beginner’s Guide

Discover how to run SQL queries in Excel to filter, join, and analyze large datasets. This beginner-friendly guide helps you automate tasks and gain deeper insights, no coding expertise required.

Run SQL query in Excel

Excel is the ideal platform for sorting and analyzing data, especially if you frequently work with such information. However, Excel has built-in tools that are crippling when your sheets grow large or you require more in-depth analysis. What happens if you continue using the familiar Excel layout and then add the powerful SQL querying capability to it?

This tutorial will demonstrate to you how to run SQL queries directly in Excel. Filtering, joining, aggregation, and manipulation of data will be possible in an efficient way. This tutorial will take you through every process, irrespective of whether you are a novice learner of SQL or you are eager to improve your Excel abilities.

When you master this technique, you will be able to work with difficult data tasks, automate some of the functions that you do repeatedly, and see patterns more effectively. To develop these skills further, they can be honed in a SQL Data Analysis Course.

What happens when you run SQL queries in Excel?

Excel has gained popularity because it is simple to learn and use, though it does not serve well when it comes to complex data analysis procedures. Having the ability to execute SQL queries in Excel is a game-changer.

1. Processing huge amounts of data

Your Excel program can be slow because of an excessive number of rows or columns on one sheet, an excessive number of formulas, or pivot tables. SQL is developed in a way to be able to manage large data volumes and perform complex queries.

2. Easy execution of advanced queries

SQL is a computer program that allows you to join tables, filter data, and classify information to perform calculations. This can be done fast using Excel with SQL. It could be very time-consuming and laborious in Excel alone.

3. Automation and renewal of information:

SQL allows you to specify a query that will be updated automatically whenever the underlying data has changed. This ensures your reports are up to date with no additional effort required.

4. Integration of data

SQL in Excel can extract the data not just in Excel but also in other databases such as SQL Server, Access, or cloud-based databases. This makes your analysis open.

How to Run SQL Queries in Excel: Step-by-Step

Running SQL query in Excel

Let’s walk through the steps you must follow to start running SQL queries in Excel.

Step 1: Open Excel and Enable Power Query or Microsoft Query

The Power Query is an effective Excel add-on. It enables the importation of data, editing, and querying in SQL-like statements. The exact process can be undertaken even when using an earlier version of Excel by utilizing Microsoft Query.

To start:

  • Go to the Data tab.
  • Look for Get Data or From Other Sources.
  • Choose your data source, which could be an Excel table, an Access database, or a SQL Server.

Step 2: Connect to Your Data Source

You can run SQL queries on:

  • Data within Excel (tables or ranges).
  • External databases like SQL Server, MySQL, or Access.
  • Online sources such as SharePoint or Azure.

Select the appropriate data connection type and follow the prompts to connect.

Step 3: Write Your SQL Query

Once connected, you can enter SQL code to query your data.

Example: Select all sales records for the West region.

SELECT * FROM SalesData WHERE Region = 'West'

Example: Calculate total sales by product category.

SELECT ProductCategory, SUM(SalesAmount) AS TotalSales FROM SalesData GROUP BY ProductCategory

The exact SQL syntax may depend on the data source, but basic commands like SELECT, WHERE, GROUP BY, and ORDER BY work consistently.

Step 4: Load the Data into Excel

After running the query, you can load the results into an Excel worksheet or into the data model for use with PivotTables or Power BI.

Step 5: Refresh Your Data

If your underlying data changes, you can refresh the query easily:

  • Go to the Data tab.
  • Click Refresh All to update all queries and connections.

Practical Examples of Running SQL Queries in Excel

Here is a real-world example of how SQL queries can improve your Excel data work.

Problem Statement

For example, a company stores customer and sales data in Excel. They desire to learn fast about customer activity and revenue. To do this, they should:

  • Filter customer lists to identify customers in a specific city and with total purchases above a certain threshold.
  • Summarize sales data to calculate monthly sales totals for each product category.
  • Join customer and order data to identify customers who made orders after a specific date, along with their order details.

The existing system in the company is based on manual filters, complicated calculations, and the combination of tables, which are time-consuming and error-prone. Instead, it would be preferable to utilize SQL statements.

Solution:

To address the problem, we can use SQL queries within Excel to complete the tasks more efficiently:

Example 1: Filtering Customer Lists

Instead of manually filtering thousands of rows, write a SQL query to pull customers from a specific city or with purchases above a certain amount.

SELECT * FROM Customers WHERE City = 'New York' AND TotalPurchases > 5000

Example 2: Summarizing Sales Data

Calculate monthly sales totals grouped by product category with one simple SQL query instead of multiple Excel formulas.

SELECT ProductCategory, MONTH(SaleDate) AS SaleMonth, SUM(SalesAmount) AS TotalSales

FROM SalesData

GROUP BY ProductCategory, MONTH(SaleDate)

ORDER BY SaleMonth

Example 3: Joining Data from Multiple Tables

SQL lets you join data from multiple sources, such as customer details and their orders, in one query, something difficult in pure Excel.

SELECT c.CustomerName, o.OrderID, o.OrderDate

FROM Customers c

JOIN Orders o ON c.CustomerID = o.CustomerID

WHERE o.OrderDate > '2023-01-01'

The Scope and Benefits of Learning SQL Queries in Excel

Knowing how to run SQL queries in Excel opens up many career and business opportunities:

  • Data Analysts: Quickly manipulate and analyze data without switching tools.
  • Finance Professionals: Streamline financial reports with automated SQL queries.
  • Marketing Teams: Segment customer data easily for targeted campaigns.
  • Small Business Owners: Manage Sales and Inventory Data More Effectively.

Industry reports show that SQL remains one of the most in-demand skills for data-related roles. Combining it with Excel expertise makes you highly versatile and valuable in today’s job market.

  • Over 750 million people use Excel as the most popular business tool in the world.
  • More and more employers are in search of individuals who can use SQL queries with Excel reports to develop automated, accurate reports.

The ability to master SQL in Excel makes you the leader in this movement and future-proof your career.

Conclusion: Take Your Excel Skills to the Next Level with SQL

When you run SQL queries through Excel, you can work with bigger data, do a more advanced analysis and automate your workflow all in the comfort of Excel.

This is the skill that is in the middle between the power of databases and the flexibility of spreadsheets, and makes you more efficient and insightful. To develop this skill, you can consider taking a data analytics SQL course so that you can be in a better position to analyze data.

Frequently Asked Questions(FAQ’s)

1. What is the benefit of running SQL queries in Excel?
SQL queries in Excel allow you to work with larger data more conveniently, create complicated queries faster, create automated updates, and combine the information in different places.This makes Excel more powerful, and it is faster and accurate in executing data analysis. In order to get the most out of these advantages, learn SQL for data analysis to help you get the best out of your data and also work more efficiently.

2. How do I enable Power Query or Microsoft Query in Excel?
In order to execute Power Query in Excel, please select Data and then Get Data or From Other Sources. In case you are using an older version of Excel, Microsoft Query can be found in the same Data tab. You should follow the instructions to connect to your data source.

3. Can I run SQL queries on external databases with Excel?
Indeed, Excel is capable of SQL queries to Excel table databases and external databases, including SQL Server, MySQL, and Access. You may also access online resources such as SharePoint or Azure to query.

4. What kind of SQL queries can I run in Excel?
SQL contains four main statements which assist you to filter information, aggregate information and manipulate information. They are SELECT, WHERE, GROUP BY and ORDER BY. With their help, you can filter a list of customers, summarize sales data, or unite the data in two or more tables.

5. How do I refresh data in Excel after running a SQL query?
Once you have run an SQL query, you refresh your data by going to the Data tab in Excel and then clicking on the “Refresh All” option. This will refresh each query and connection, therefore keeping your data up to date.

6. What are some practical examples of using SQL queries in Excel?
Excel SQL queries assist you in your daily activities, i.e., filtering a list of customers according to some criteria, the aggregation of sales according to some type of products, and the joining of two or more tables, i.e., the description of customers and their orders.

7. How can learning SQL in Excel benefit my career?
When you know SQL in Excel, you have new opportunities in most fields. It assists data analysts, finance, marketing, and small business owners to work more quickly, automate operations, and discover more insights in their data. Since SQL is a highly demanded skill, including it in your Excel skill set will make you a marketable individual.

Avatar photo
Great Learning Editorial Team
The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.

Academy Pro Subscription

Grab 50% off
on Top Courses - Free Trial Available

×
Scroll to Top