SQL Queries add-in: 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

Screenshot: main features of XLTools SQL Queries


Add "SQL Queries" to Excel 2019, 2016, 2013, 2010

Works in: Microsoft Excel 2019 – 2010, desktop Office 365 (both 32 bit and 64 bit).

Download XLTools Add-in

SQL Queries ribbon button in Excel


Learn your way around:


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 click ‘Format 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 turn Excel data into relational database before running sql queries


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 the ‘Execute SQL’ button 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.
    Note: 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!

How to generate SELECT statement with XLTools SQL Queries


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


XLTools uses SQLite 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: instead of typing table names, simply drag and drop the names from the tree area to the SQL editor area.


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. Click ‘Execute SQL’ on 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.

How to left join Excel tables with XLTools SQL Queries add-in

Any questions or suggestions? Please leave your comment below.

22 Responses to SQL Queries add-in: the power of SQL to run queries in Excel and directly on Excel tables

  1. John Miller says:

    Is there support for checking blank or null cells in the SQL Query tool?

    • Maria Balobanova says:

      Hi John,
      XLTools uses SQLite and it supports IS NULL and IS NOT NULL operators – you can use them your query.

  2. Sisir says:

    Can we use DATEDIFF functions here? I tried a couple of different combinations and doesn’t seem to work. Appreciate your help.

    • Maria Balobanova says:

      Hi 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.

  3. Amy B Sessler says:

    Can Case statements be executed using this tool

  4. Sayth Renshaw says:

    Noticed when I saved file locally worked fine. When filed stored in Onedrive it fails to find the workbook.

  5. Matt F says:

    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.

    • Maria Balobanova says:

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

      In the meanwhile, please try this: download XLTools again > 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.

  6. Marcio Mollica says:

    Is there a version of this add-in for Mac OS?

    • Maria Balobanova says:

      No, Marcio, XLTools desktop is for Windows only.

      You may be interested in our SQL Queries app – it has similar functionality and works in Excel for Mac. The app is available in Microsoft Office Store.

  7. Baba Andhale says:

    Dear 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

    • Maria Balobanova says:

      Hi 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 our Automation feature to run SQL queries against Excel tables without VBA scripting.

  8. Deepak R. Rechwad says:

    Hello 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

    Deepak R. Rechwad
    (India, Mumbia)

    • Maria Balobanova says:

      Dear 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.

  9. Tuomo says:

    What if anything does this tool have that Microsoft’s free Power Query add-on doesn’t?

    • Maria Balobanova says:

      Hi 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.

  10. Mor Sagmon says:

    Is 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)?

  11. Dana says:

    SQL 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

  12. Julian says:

    I 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?

    • Peter Liapin says:

      Hello 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.

Leave a Reply to Sayth Renshaw Cancel reply

Your email address will not be published. Required fields are marked *