Use the power of SQL to run queries in Excel and directly on Excel tables

Often Excel tables gradually grow into large inconvenient workbooks. Finding duplicates, filtering, grouping, complex sorting, joining tables into one, etc. – become a real challenge. Potentially, these tasks could be easily executed with SQL… if only it were possible to run SQL queries against Excel data.

XLTools SQL Queries add-in enhances Excel with the power of structured query language:

  • Run SQL queries in Excel interface and directly on Excel tables
  • Generate SELECT and JOIN statements automatically
  • Use JOIN, ORDER BY, DISTINCT, GROUP BY, SUM and other SQLite operators
  • Write queries in the intuitive editor with syntax highlighting
  • Address any Excel tables from a tree list view

How to turn your Excel data into a relational database and prepare for SQL querying

By default, Excel presents data as simple data ranges. But SQL works only with relational data sources. So before you begin, make sure to format Excel ranges as tables (named ranges with table style applied):

  1. Select the data range On the Home tab clickFormat as Table Select a table style.
  2. Select the table Open the Design tab Type in the Table Name.

    E.g. "ProductID"

  3. Repeat these steps for each data range that you plan to use in SQL queries.

    E.g. tables "RetailPrice", "SalesVolume", etc.

  4. Done, now these tables will serve as a relational database and are prepared for querying.

How to create and run SQL SELECT on Excel tables

SQL Queries add-in allows you to execute queries on Excel tables located in different worksheets and different workbooks. Please make sure that these workbooks are open and the necessary data are formatted as named tables.

  1. Click theExecute SQLbutton on the XLTools tab The editor window will open.
  2. On the left-hand side find a tree view of all available tables.

    Click on the nodes to expand/collapse table fields (columns).

  3. Select entire tables or specific fields.

    As you tick the fields, SELECT statement is generated automatically in the right-hand side area of the editor.
    Tip:watch the SQL editor automatically highlight syntax.
  4. Choose whether to place the query output on a new or an existing worksheet.
  5. Click Run Done!

Operators Left Join, Order By, Group By, Distinct, and other SQLite commands in Excel

XLTools usesSQLite syntax. Users who are familiar with SQLite can execute a wide variety of queries:

  • LEFT JOIN – join two or more tables by shared key columns
  • ORDER BY – sort data in query results
  • DISTINCT – remove duplicates from the query output
  • GROUP BY – group data in query results
  • SUM, COUNT, MIN, MAX, AVG and other operators
Tip:watch the SQL editor automatically highlight syntax.

How to join two or more Excel tables with SQL Queries add-in

You can merge multiple Excel tables into one if they have a shared key field. Suppose you have to join a few tables that share a column "ProductID":

  1. ClickExecute SQLon XLTools tab Select the fields you want to see in the merged table.

    As you tick the fields, SELECT and LEFT JOIN get generated automatically.

  2. Choose whether to place the query output on a new or an existing worksheet.
  3. Click Run Done! A merged table appears in seconds.
Any questions or suggestions?
John MillerIs there support for checking blank or null cells in the SQL Query tool?
March 8, 2020 at 20:03
Maria BalobanovaHi John, XLTools uses SQLite and it supports IS NULL and IS NOT NULL operators - you can use them your query.
March 10, 2020 at 13:01
SisirCan we use DATEDIFF functions here? I tried a couple of different combinations and doesn't seem to work. Appreciate your help.
October 5, 2019 at 01:13
Maria BalobanovaHi Sisir, our add-in is based on SQLite language. SQLite, however, does not support the DateDiff function. There are workarounds, e.g. subtracting one date from the other to get the difference.
October 7, 2019 at 12:16
Amy B SesslerCan Case statements be executed using this tool
November 2, 2018 at 22:25
Maria BalobanovaHi Amy, yes, this add-in uses SQLite syntax, andCASE expressionsare supported as well.
November 6, 2018 at 14:47
Sayth RenshawNoticed when I saved file locally worked fine. When filed stored in Onedrive it fails to find the workbook.
October 3, 2018 at 13:33
Maria BalobanovaHi Sayth, Thank you for reporting this. We will definitely look into this issue!
October 3, 2018 at 16:09
Matt F

Certificate errors during install, would love to try.   Name: XLTools Add-In for Microsoft Excel From: https ://xltools.net/clickonce/pro/en/XLTools.vsto ************** Exception Text ************** System.Security.SecurityException: Customized functionality in this application will not work because the certificate used to sign the deployment manifest for XLTools Add-In for Microsoft Excel or its location is not trusted.

January 18, 2018 at 21:07
Maria Balobanova

Hello Matt, thank you for reporting the error! We will look into it.

In the meanwhile, please try this:download XLToolsagain > Save the file > Run ‘XLTools.exe’ and follow the setup wizard > If you are prompted to install Microsoft prerequisites along the way, please do so.

January 19, 2018 at 12:45
Marcio MollicaIs there a version of this add-in for Mac OS?
August 17, 2017 at 20:33
Maria BalobanovaNo, Marcio, XLTools desktop is for Windows only. You may be interested inour SQL Queries app- it has similar functionality and works in Excel for Mac. The app is available in Microsoft Office Store.
August 17, 2017 at 20:51
Baba AndhaleDear sir, I have downloaded XLTools and created a query as I need. But I have to save its name and have to run with macro. How it will be done, Pls guide
July 21, 2016 at 07:00
Maria BalobanovaHi Baba, Thank you for your interest in XLTools! You can copy the query text in the SQL Queries editor and use it in your macro, if that's what you mean. Or you can try ourAutomation featureto run SQL queries against Excel tables without VBA scripting.
July 25, 2016 at 14:16
Deepak R. RechwadHello sir, as we are sql programing developer, can we use your XLTools PRO for deployment to our client? direct generate their report in excel? pls guide me Thanks Deepak R. Rechwad (India, Mumbia)
January 8, 2016 at 14:20
Maria BalobanovaDear Deepak, Thank your for your interest in XLTools! You can create and run reports with XLTools SQL Queries for your customers. Please note, that if you plan to deploy XLTools at your customer's computers as well, they will also need the PRO license. Number of computers = Number of Licenses. Before buying the PRO license, I strongly advise that you take the free trial and see if XLTools SQL Queries will be suitable for the reports you want to develop. Once you download the XLTools add-in, you will automatically receive the free trial license to your email. Let me know if any questions.
January 11, 2016 at 15:12
TuomoWhat if anything does this tool have that Microsoft's free Power Query add-on doesn't?
October 9, 2015 at 11:38
Maria BalobanovaHi Tuomo, these are two different tools for different purposes. Microsoft Power Query add-in allows working with external data. SQL Queries by XLTools is the add-in that enables data analysis directly Excel. Basically, you can create and run queries directly against Excel tables using SQL language. You can have both add-ins on you computer.
October 9, 2015 at 15:23
Mor SagmonIs the resulting table "live"? meaning, linked to the data sources and automatically calculated upon changes to the source tables (like Excel calculates dependent cells automatically)?
June 5, 2015 at 20:43
DanaSQL Query confusion .... FREE .... Buy 19.95 ..... Free Trial or 6.99 month. Is there a difference between 19.95 version and the 6.99 per month version .... I am running Excel 2013 .... Price? — It's FREE! .. really misleading. Please advise ... Thank you, Dana Masters
June 4, 2015 at 23:59
JulianI assume this allows you to query worksheets in the SAME workbook? If so and I distribute that workbook to members of my team will the queries work if the members don't have SQL query add on installed?
February 6, 2015 at 08:37
Peter LiapinHello Julian, On this page we have information about our COM add-in which can not be embedded in a single workbook, so all your team members who need SQL Queries will need to install XLTools Add-In too. By the way it allows to run SQL query across multiple tables in a multiple workbooks if you open them all at the same time.
February 6, 2015 at 14:07
How can we help?